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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.