我有一个Android应用程序,它通过HTTP Post与服务器通信。
以下是代码,url_select为“http://example.com/Padua/rest/messages/messagetodelete”
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost post = new HttpPost(url_select);
post.setEntity(new ByteArrayEntity(message.toString().getBytes("UTF8")));
HttpResponse response = client.execute(post);
这很有效,我可以在服务器中获取消息。但是,当我尝试在iPhone中实现这一点时,我很震惊。我不知道如何做到这一点。在Exact中,NSMutalbleURLRequest中的setentity部分
以下是代码
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[NSURL URLWithString:@"http://example.com/Padua/rest/messages/messagetodelete"];
[request setURL:[NSURL URLWithString:@"http://example.com/Padua/rest/messages/messagetodelete"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//This is where I am getting confused. How to pass the messageid to the URL??
[request setHTTPBody:messageid];
//This is where I am getting confused
NSLog(@"JSON summary: %@", [[NSString alloc] initWithData:messageid
encoding:NSUTF8StringEncoding]);
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
任何人都可以帮助我。我需要在iOS中传递URL本身的messageid,就像在Android中一样。 谢谢,如果您需要任何附加信息,我会为您提供