3

I need a simple example where we POST some HTTP request to the server. And also i need to add some headers to that HTTP post. I have tried posting the HTTP post, but little confused about adding headers in the request. Is there any mandatory field/HEADER i have to add in the HTTP Post ??

4
  • You mean , the content-length is mandatory ? Commented Jan 31, 2012 at 13:49
  • 1
    Depending on exactly what you're trying to send, it may well be. You could POST form values, multipart messages or even several things in succession (like from a streaming response, where you don't know the length up front). Commented Jan 31, 2012 at 16:10
  • Any example for Http Post where i can add the headers also in that ?? Commented Feb 1, 2012 at 7:39
  • As I said, it depends on how you're passing the values. The accepted answer tells you how to set the header, but the way you're passing the POST data will answer what to send. In most cases it's the number of bytes in the binary data you're posting, but I encourage you to find out specifically how you're sending data so that you can work this out for yourself. Since you didn't describe your scenario, I can't tell you what will work. Commented Feb 2, 2012 at 8:58

1 Answer 1

1

Suppose you have an NSURLRequest called theRequest.

You configure the request type to POST with

[theRequest setHTTPMethod:@"POST"];

And for the headers, you add values to the Header you add them as key value pairs:

[theRequest setValue:authorizationString forKey:@"Authorization"];

which sets authorizationString for the Authorization header.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there any example for HTTP post along with adding the headers with the post ? can u give me ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.