Skip to main content

nsurlrequest settings for POST



I am setting up a request to my server, I have been helped out with a few suggestions but I am wanting some clarification on a part of code.





in the second line of code, what are the setValue: and forHTTPHeaderField: values used for? I'm thinking forHTTPHeaderField: sets the mime type... but im not sure what setValue is for or how it effects my request.







[request setHTTPMethod: @"POST"];

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];

[request setHTTPBody:postBodyData];







any help would be greatly appreciated.


Comments

  1. See the NSMutableURLRequest reference for the method description and HTTP documentation at 14.17 Content-Type section for the header information.

    More C-T details at the section 7.2.1


    Content-Type specifies the media type of the underlying data. Content-Encoding may be used to indicate any additional content codings applied to the data, usually for the purpose of data compression, that are a property of the requested resource. There is no default encoding.

    Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If
    and only if the media type is not given by a Content-Type field, the
    recipient MAY attempt to guess the media type via inspection of its
    content and/or the name extension(s) of the URI used to identify the
    resource. If the media type remains unknown, the recipient SHOULD
    treat it as type "application/octet-stream".

    ReplyDelete
  2. Every HTML request consists of a request header and body.

    In your example you define that the body of this request contains form data.

    If for example you want to submit a json structure as your request body, the content type of the request is to be set as "application/json".

    ReplyDelete
  3. In the case of content-type, it would be things like text/html, text/xml, or image/gif.

    The purpose here is to specify what type of data is being transmitted.

    For header field definitions, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.

    For the different media types, see http://en.wikipedia.org/wiki/Internet_media_type.

    Also see the NSURLRequest reference for specifics of that class.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...