Key is> hi
Value is> hello
我需要将此值发送到server.Consider我的网址为https://mywebsite/myserver/upload
如何通过HTTP POST方法将这些值发送到IOS中的服务器。
答案 0 :(得分:0)
这是您可以将密钥对值作为请求正文的一部分发送的方法
NSString *myKeyValuePairString = @"hi=hello";
NSData *myRequestData = [NSData dataWithBytes:[myKeyValuePairString UTF8String] length:[myKeyValuePairString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: @"https://mywebsite/myserver/upload"]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
如果作为标题的一部分
[request setValue:@"hello" forHTTPHeaderField:@"hi"];