简体   繁体   English

如何将价值传递给我想在我的应用程序中使用的Web服务?

[英]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.

相关问题 如何在iPhone应用程序中使用Web服务? - how to make use of web service in iphone app? 如何使用深层链接我想使用消息应用程序打开我的应用程序? - How to use deep link I want to open my app with using message app? 如何从iPhone应用程序中将用户名和密码传递到Web服务? - How to pass username and password to a web service from within an iPhone app? 如何验证从iphone应用程序到我的Web服务的请求的真实性 - How can I verify the authenticity of requests from an iphone app to my web service 我想在我的iphone应用程序中使用或检测消息中存在的消息 - I want to use or detect message present in Messages, in my iphone app 我想为我的iPhone应用程序使用推送通知 - I want to use Push Notification for My app for IPhone 如何在iPhone设备文件系统中存储图像,以便以后我可以检索它并在我的应用程序中使用? - How can I store an image in the iPhone device file system so that later if I want I can retrieve it and use in my app? 当我想消耗我的Web服务时发生运行时错误 - when i want to consume my web service occur run time error Swift:我想从csv文件中读取具有许多属性的国家/地区列表,并将其用于我的应用程序。 我该如何实施? - Swift: I want to read a list of countries with many attributes from a csv files and use this for my app. How can I implement this? 如何使用NSURLSession在我的Web服务调用中使用NSURLCache - How to use NSURLCache with My Web service calls using NSURLSession
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM