[英]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. 我正在尝试在应用程序中使用Web服务。 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.
我正在尝试使用此服务:http://www.w3schools.com/webservices/tempconvert.asmx此服务将摄氏温度转换为华氏温度,反之亦然。 So it also needs some value to convert.
因此,它还需要一些值才能进行转换。 Please share some info 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. 如果您不熟悉HTTP,那么您需要做的第一件事就是做一些阅读以了解基础知识。
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. 一旦了解了HTTP的基础知识,便可以了解该服务要求您执行HTTP
POST
以获取所需的值。
If you read the documentation of the endpoint, you'll see that you need to POST
to a specific resource. 如果您阅读了端点的文档,您将看到需要对特定资源进行
POST
。 The contents of the POST
request headers should look like this: POST
请求标头的内容应如下所示:
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
. 接下来,您需要在
POST
的请求正文中放入一些内容。 This request body should look like this: 该请求正文应如下所示:
Celsius=50
Where 50
is the temperature in Celsius. 温度为摄氏
50
度。
Now, you need to actually translate this HTTP POST
into code. 现在,您实际上需要将此HTTP
POST
转换为代码。 Here are a number of URLs with examples: 以下是一些带有示例的URL:
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. 该示例使用SOAP(SOAP是一种XML对象交换格式),我主要使用JSON,您将使用YAML或基于XML或您希望的任何其他结构的自己的特殊布局。
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. 您可以使用现成的SOAP库,使用google搜索将是一个不错的选择。 for JSON I use SB JSON, I haven't ever used a SOAP library on the iPhone.
对于JSON,我使用SB JSON,但我从未在iPhone上使用过SOAP库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.