NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.someurl.com"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn)
{
receivedData = [[NSMutableData data] retain];
}
else
{
// inform the user that the download could not be made
}
发送数据的
下栽数据的
- (void) URLTest
{
NSString *url = @"http://earthquake.usgs.gov/images/globes/-5_130.jpg";
NSURLRequest* theRequest = [NSURLRequest requestWithURL: [NSURL URLWithString: url] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 60.0];
NSURLConnection* theConnection = [[NSURLConnection alloc] initWithRequest: theRequest delegate: self];
if(theConnection)
{
// Create the NSMutableData that will hold the received data
// receivedData is declared as a method instance elsewhere
receivedData = [[NSMutableData data] retain];
[self showAlertWithTitle: @"URL Test" message: @"Download could be made"];
}
else
{
// inform the user that the download could not be made
[self showAlertWithTitle: @"URL Test" message: @"Download could not be made"];
}
}
分享到:
相关推荐
基于NSMutableURLRequest发起的网络请求,在请求的同时加上加载框和提示框
NSMutableURLRequest-Upload, 专门针对文件上传的 NSMutableURLRequest 分类
框架使用说明1、将NSMutableURLRequest+MutilPartForm.h和NSMutableURLRequest+MutilPartForm.m分类导入到项目中2、导入NSMutableURLRequest+MutilPartForm.h3、修改NSMutableURLRequest+MutilPartForm.m文件上传...
代码如下: // 组合一个搜索字符串 ... // 字符串转化为URL NSURL *url = [NSURL URLWithString:urlStr];...// NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; // [request setURL:url]; //
http NSMutableURLRequest
用NSMutableURLRequest *request
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]init];//客户端向服务端请求的类 [request setURL:[NSURL URLWithString:strURL]];//设置http地址 [request setHTTPMethod:@"POST"];//设置发送方法 ...
host, relative path, query, fragment,包括一个可以放置重复key-value的DuplicatableDictionary),一个完善的OAuthv1库(C函数实现,但使用cocoa对象作参数)及相对应的NSMutableURLRequest和ASIHTTPRequest的...
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:url]; //设置请求方式 [request setHTTPMethod:@"GET"]; //设置请求超时的时间 [request setTimeoutInterval:60]; /...
给阿凯的demo NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
里为大家整理了iOS的HTTP请求和请求回执类用法小结,包括发送请求的NSURLRequest、NSMutableURLRequest和负责回复的NSURLResponse类的常用方法和属性,需要的朋友可以参考下
FMAssetStream ...然后在你的 NSMutableURLRequest 上使用setAsset : NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://example.com/
8.4 Modifying a URL Request with NSMutableURLRequest 482 8.5 Sending HTTP GET Requests with NSURLConnection 483 8.6 Sending HTTP POST Requests with NSURLConnection 486 8.7 Sending ...
You will learn how to integrate a number of Unix (BSD Sockets), Apple specific (CFNetworking, NSMutableURLRequest, Bonjour) and third party APIs (AFNetworking, MKNetworking) with your own apps.
问题描述: iOS9和iOS10用WKWebView加载URL都没有问题,iOS11却是一片空白 可能是用了 NSMutableURLRequest ,iOS11貌似不支持 NSMutableURLRequest ,无论是用 UIWebView 还是 WKWebView ,都不支持 NSMutableURLRequest...
它只需要 NSURLRequest(或 NSMutableURLRequest)的实例。 所有请求都存储在队列中。 请求管理器从队列中提取头请求并运行它。 依此类推,直到队列为空。安装在您的项目中安装Request Manager的推荐方法是通过 。 ...
本文通过实例代码给大家讲解iOS中以application/json上传文件的形式,具体内容详情大家参考下本文。... NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:acces
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@https://imgchr.com/json] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; NSDictionary *...
NSMutableURLRequest *rq = [OMGHTTPURLRQ GET: @" http://api.com " :@{ @" key " : @" value " }];// application/x-www-form-urlencodedNSMutableURLRequest *rq = [OMGHTTPURLRQ POST: @" ...