当我使用iPhone执行HTTP POST请求时,HTTP标头消失

时间:2013-12-05 05:46:01

标签: php objective-c http post http-headers

我是Objective c的新手,我遇到了一个问题,仅在我执行HTTP POST请求时出现
我用我的iPhone做HTTP请求,我希望服务器在标题中返回这样的内容(这是来自其他服务器的响应头):

{
"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = close;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "something";
Expires = "something";
Location = "/mylocation/10"; <--- this is what i want
Pragma = "no-cache";
Server = "Apache/2.2.3 (CentOS)";
"Set-Cookie" = "something";
"X-Powered-By" = "PHP/5.3.3";
}

当我成功发布时,它会执行想要的功能,并返回一个带有标题的空响应:

{
"Cache-Control" = "max-age=0, no-cache";
Connection = close;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "something";
Server = "Apache/2.2.14 (Ubuntu)";
}

即使我添加标题如“Cache-Control”=“no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0”,它们也不会显示在响应头中。
我该怎么做才能得到正确的标题?

其他信息
我使用ASIFormDataRequest来发出请求,这是我设置头的代码:

{
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:something];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Authorization" value:@"something"];
[request addRequestHeader:@"Accept" value:@"application/json,*/*;q=0.8"];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
}


这就是我得到回复标题的方式:

{
[request startSynchronous];
NSLog(@"%@", [request responseHeaders]);
}

1 个答案:

答案 0 :(得分:0)

仅在重定向期间发送位置标头。当我们使用PUT方法添加资源时,新创建的URL将添加到Location头中,并将作为响应的一部分发送。这也发生在3xx重定向期间。