开发者

Do a GET request with parameters on iPhone SDK?

开发者 https://www.devze.com 2023-03-11 16:22 出处:网络
I\'m doing an app which retrieves user info, and it does that using a GET request, but I don\'t know how could I make one. Already tried ASIHTTPRequest with this code:

I'm doing an app which retrieves user info, and it does that using a GET request, but I don't know how could I make one. Already tried ASIHTTPRequest with this code:

    NSURL *url = [NSURL URLWithString:@"http://forrst.com/api/v2/users/info"];
    // Now, set up the post data:
    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];

    [request setPostValue:@"1" forKey:@"id开发者_运维知识库"];
    [request setRequestMethod:@"GET"];

    // Initiate the WebService request
    [request setDelegate:self];
    [request startAsynchronous];

But I get this response from forrst:

2011-06-05 16:59:32.189 Forrsty[4335:207] {"resp":{"error":"you must pass either id or username"},"stat":"fail","in":0.0557,"authed":false,"authed_as":false,"env":"prod"}

Which I understand I'm not doing the GET request ok, so how I would do it? Thanks :)


A Get Parameter ?

So why don't you try "http://forrst.com/api/v2/users/info?id=1" ?

[ NSString stringWithFormat:@"http://forrst.com/api/v2/users/info?id=%d", 1 ];

By the way, take a look at this librayry : http://allseeing-i.com/ASIHTTPRequest/

Good luck !

0

精彩评论

暂无评论...
验证码 换一张
取 消