iphone发送数据到服务器端有多种方法
来源:互联网 发布:win10优化工具 推荐 编辑:程序博客网 时间:2024/06/05 00:14
iPhone HTTP Post发送数据
-(NSString *)MyUrl:(NSString *)urlStr
{
NSURL *url;
NSMutableURLRequest *urlRequest;
NSMutableData *postBody = [NSMutableData data];
url = [NSURL URLWithString:@"http://ceshixieyi.appspot.com/ceshixieyi..."];
urlRequest = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
[urlRequest setHTTPMethod:@"POST"];
//NSString *udid = @"U0020 #999999#E3CEB5881A0A1FDAAD01296D7554868D#";
[postBody appendData:[urlStr dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion:YES]];
[urlRequest setHTTPBody:postBody];
NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
NSString *result = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
if(returnData)
{
NSLog(@"%@",result);
}
else
{
NSLog(@"error!");
}
return result;
}
是这样调用的NSString *udid = @"U0020 #999999#E3CEB5881A0A1FDAAD01296D7554868D#";
[self MyUrl:udid];
2、使用SOAP方法
NSMutableString *sRequest = [[NSMutableString alloc] init];
// Create the SOAP body
[sRequest appendString:@"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:u=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"];
// This is the header section it is expecting in the body
[sRequest appendString:@"<s:Header>"];
[sRequest appendString:@"<o:Security s:mustUnderstand=\"1\" xmlns:o=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"];
// This is where you pass in the user id and password. This is sent in the body header as clear text, but since you will be using HTTPS it will be somewhat encrypted.
[sRequest appendString:@"<o:UsernameToken>"];
[sRequest appendString:@"<o:Username>"];
[sRequest appendString:@"DIFZ"];
[sRequest appendString:@"</o:Username>"];
[sRequest appendString:@"<o:Password>"];
[sRequest appendString:@"TheBest!"];
[sRequest appendString:@"</o:Password>"];
[sRequest appendString:@"</o:UsernameToken>"];
[sRequest appendString:@"</o:Security>"];
[sRequest appendString:@"</s:Header>"];
// This is the body where you can pass in any parameters the WCF service expects
[sRequest appendString:@"<s:Body>"];
[sRequest appendString:@"<GetWeeksList xmlns=\"http://tempuri.org/\"></GetWeeksList>"];
[sRequest appendString:@"</s:Body>"];
[sRequest appendString:@"</s:Envelope>"];
// The URL of the Webserver
NSURL *myWebserverURL = [NSURL URLWithString:@"https://[Server URL]/FootballPool_DAL/GameData.svc"];
// Use the private method setAllowsAnyHTTPSCertificate:forHost:
// to not validate the HTTPS certificate. This is used if you are using a testing environment and have
// a sample SSL certificate set up
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL];
// Add the Required WCF Header Values. This is what the WCF service expects in the header.
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://tempuri.org/IGameData/GetWeeksList" forHTTPHeaderField:@"SOAPAction"];
// Set the action to Post
[request setHTTPMethod:@"POST"];
// Set the body
[request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
// Create the connection
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
// Check the connection object
if(conn)
{
myMutableData=[[NSMutableData data] retain];
}
// Make this class the delegate so that the other connection events fire here.
[NSURLConnection connectionWithRequest:request delegate:self];
NSError *WSerror;
NSURLResponse *WSresponse;
// Execute the WCF Service and return the data in an NSMutableData object
myMutableData = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror];
// Return the data to the caller for processing
return myMutableData;
}
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host
{
return YES;
}
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host
{
}
- iphone发送数据到服务器端有多种方法
- 从客户端,通过HttpClient发送二进制数据到服务器端
- 从客户端,通过HttpClient发送二进制数据到服务器端
- 震惊,超出数据范围有这么多种方法,活久见!
- html5-向服务器端发送数据
- iPhone发送图片到服务器
- ajax之jason发送到服务器端
- ios发送json数据格式到服务器端
- iPhone多线程(多种实现方法)二
- Android向服务器端发送json数据
- 通过wifi向服务器端发送数据
- Android向服务器端发送json数据
- 客户端发送xml数据,服务器端接收之
- 转载:多种方法使用Java发送电子邮件
- 发送数据到服务器
- 发送数据到Flume
- Android GET,POST向服务器端发送数据(发送)
- Android GET,POST向服务器端发送数据(发送)
- Subquery returns more than 1 row
- 真是情何以堪呢
- jquery 表格的增加删除和修改及设置奇偶行颜色
- 多线程笔记
- (转)大型数据库设计原则
- iphone发送数据到服务器端有多种方法
- selenium 学习2
- LINUX下RPM的使用方法
- ORACLE PL/SQL编程详解之一
- linux基础指令
- 让ubuntu支持windows编码
- 基于OHCI协议的S3C2440 USB Host Driver之协议介绍(二)
- 销售订单增强
- selenium 学习3