开发者

How to pass value to a Web service i want to use in my app?

I am trying my hands on using web services in my app. I am trying to use this service:http://www.w3schools.com/webservices/tempconvert.asmx This service converts temp in celsius to fahrenheit and vice versa. So it also needs some value to convert. Please share some info开发者_如何学JAVA on this. A code snippet will be great or any tutorial or sample app.

Thanks,


If you aren't familiar with HTTP, the first thing you need to do is do a bit of reading to understand the basics.

Once you understand the basics of HTTP, you can then understand that the service requires you to perform an HTTP POST to get the value you want.

If you read the documentation of the endpoint, you'll see that you need to POST to a specific resource. The contents of the POST request headers should look like this:

POST /webservices/tempconvert.asmx/CelsiusToFahrenheit HTTP/1.1
Host: www.w3schools.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

Next, you need to put some content in the request body of the POST. This request body should look like this:

Celsius=50

Where 50 is the temperature in Celsius.


Now, you need to actually translate this HTTP POST into code. Here are a number of URLs with examples:

  • http://www.deanoj.co.uk/ios-development/making-a-http-post-request-with-nsurlconnection/
  • iphone http post to public server=good, but trying on my server=bad
  • iOS: how to perform a HTTP POST request?


That Example uses SOAP, which is an XML object exchange format, I use JSON mostly, you would use YAML, or your own special layout, based on XML or any other structure you wish.

The idea is that you format your request in a way that the server will understand, and the server formats the response in a format that your app will understand, it doesn't have anything to do with actually sending the request or the response.

You can use a ready made SOAP library, a google search would be a good place for that. for JSON I use SB JSON, I haven't ever used a SOAP library on the iPhone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜