ASIHTTPRequest向请求添加标头

时间:2021-06-19 16:55:19

I am using ASIHTTPRequest, and i have to make use of the POST method to send some values to the server. So, for this i have to set headers and its corresponding values.

我正在使用ASIHTTPRequest,我必须使用POST方法将一些值发送到服务器。所以,为此我必须设置标题及其相应的值。

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request addRequestHeader:@"Referer" value:@"http://allseeing-i.com/"];

The following are headers that is needed to be included in my application, and how could i include the once with Semi-Colons ("Content-Type" = "text/html"; , "Keep-Alive" = "timeout=15, max=100"; etc)

以下是需要包含在我的应用程序中的标题,以及如何包含一次使用Semi-Colons(“Content-Type”=“text / html”;,“Keep-Alive”=“timeout = 15, max = 100“;等)

    "Content-Type" = "text/html";

    Date = "Wed, 21 Jun 2011 09:09:57 GMT";

    "Keep-Alive" = "timeout=15, max=100";

    Server = Apache;

    "Transfer-Encoding" = Identity;

2 个解决方案

#1


5  

Just use addRequestHeader in the same way as you're setting Referer. You don't need to include those semicolons - I think the ; are only there as an artifact of the method used to capture the headers. You do not use ; like that in HTTP.

只需使用addRequestHeader,就像设置Referer一样。你不需要包括那些分号 - 我认为;仅作为用于捕获标头的方法的工件。你不用;像在HTTP中那样。

eg:

[request addRequestHeader:@"Keep-Alive" value:@"timeout=15, max=100"];

#2


1  

You just have to add [request setRequestMethod:@"POST"];

你只需要添加[request setRequestMethod:@“POST”];

#1


5  

Just use addRequestHeader in the same way as you're setting Referer. You don't need to include those semicolons - I think the ; are only there as an artifact of the method used to capture the headers. You do not use ; like that in HTTP.

只需使用addRequestHeader,就像设置Referer一样。你不需要包括那些分号 - 我认为;仅作为用于捕获标头的方法的工件。你不用;像在HTTP中那样。

eg:

[request addRequestHeader:@"Keep-Alive" value:@"timeout=15, max=100"];

#2


1  

You just have to add [request setRequestMethod:@"POST"];

你只需要添加[request setRequestMethod:@“POST”];