2

iOSからWebAPIを呼び出し、メソッドPOSTを呼び出し、postメソッドでパラメーターを渡すことができません

Web API:

public class Person
{
    public int Id { get; set; }
    public String Name { get; set; }
}

 // POST api/values
public void Post([FromBody]Person value)
{

}

iOSの場合

NSURL *url =[NSURL URLWithString:@"http://localhost:9281/api/values"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];

NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];

POSTメソッドで値パラメーターPersonを渡す方法は?

4

1 に答える 1

2
NSMutableURLRequest *request = [NSMutableURLRequest 
                                    requestWithURL:[NSURL URLWithString:@"http://www.domain.com/your/servlet"]];

NSString *params = [[NSString alloc] initWithFormat:@"foo=bar&key=value"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

これはこのブログ投稿からのものです:http ://www.deanoj.co.uk/ios-development/making-a-http-post-request-with-nsurlconnection/

于 2012-12-26T16:29:43.680 に答える