【问题标题】:iOS sending a POST and GET in the same requestiOS 在同一个请求中发送 POST 和 GET
【发布时间】:2015-02-11 04:29:11
【问题描述】:

我成功发布数据如下:

     NSMutableURLRequest *scriptrequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL      URLWithString:@"myurl.com"]];

 [scriptrequest setHTTPMethod:@"POST"];

NSString *sendData =[NSString stringWithFormat:@"ID=%@&action=List", ID, nil];
NSData *scriptdata = [sendData dataUsingEncoding:NSUTF8StringEncoding];

[scriptrequest setHTTPBody:scriptdata];

NSError *scripterr;
NSURLResponse *scriptresponse;


NSData *scriptResponseData = [NSURLConnection sendSynchronousRequest:scriptrequest returningResponse:&scriptresponse error:&scripterr];

我的问题是,是否可以将 GET 数据也附加到同一个调用中?

【问题讨论】:

  • 恐怕你做不到

标签: ios json xcode post get


【解决方案1】:

在我看来,您正在尝试从服务器检索数据,而不是更新。形成请求的更典型方法是 GET http://myurl.com?ID=123&action=List。但是,这实际上取决于服务器代码的编写方式。

【讨论】:

    【解决方案2】:

    GET 和 POST 是不同类型的 HTTP 请求。

    GET 请求主要用于获取网页内容,而 POST 用于插入/更新某些内容。

    所以最终单个 HTTP 请求只能是以下之一。

    Http types include:
    
    GET
    HEAD
    POST 
    PUT
    DELETE
    TRACE
    OPTIONS
    CONNECT
    PATCH
    

    维基百科的更多技术细节: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

    【讨论】:

    • 好的,谢谢。是否可以形成与 POST 请求分开的 GET 请求并同时发送两个请求?
    • 我不确定您的要求。可能你需要解释更多。但是您仍然可以使用异步请求来获得并行执行的感觉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多