首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin Android Rest API to PassSlot - nameResolutionFailure

Xamarin Android Rest API to PassSlot - nameResolutionFailure
EN

Stack Overflow用户
提问于 2014-08-19 21:17:14
回答 1查看 600关注 0票数 0

我使用REST API访问PassSlot,试图生成通行证/优惠券。似乎当我运行程序时,我得到了一个错误:"Error: NameResolutionFailure“。

我有:

代码语言:javascript
复制
public static async Task<string> SendAndReceiveJsonRequest()
        {
            string responseStr = null;
            string uri = "https://api.passslot.com/v1/templates/my-template-ID/pass";

            // Create a json string with a single key/value pair.

            var json = new JObject (new JProperty ("lastName", lastName),
                                    new JProperty ("firstName", firstName),
                                    new JProperty ("percentOff", percentOff),
                                    new JProperty ("offerDescription", offerDescription),
                                    new JProperty ("entityName", entityName),
                                    new JProperty ("expiry", expiry));

            //Console.WriteLine ("Jake's JSON " + json.ToString ());

            using (var httpClient = new HttpClient ())

            {    

                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("My-Key-Here-xxx-xxx-xxx");
                //create the http request content

                HttpContent content = new StringContent(json.ToString());


                try
                {
                    // Send the json to the server using POST

                    Task<HttpResponseMessage> getResponse = httpClient.PostAsync(uri, content);
                    // Wait for the response and read it to a string var

                    HttpResponseMessage response = await getResponse;
                    responseStr = await response.Content.ReadAsStringAsync();

                }
                catch (Exception e)
                {
                    Console.WriteLine("Error communicating with the server: " + e.Message);
                }
            }

            return responseStr;
        }

我是通过Nexus 4在Android 4.4上运行这个程序的,我用的是3G (不是wifi)。

任何关于这里可能发生的事情以及为什么我会收到错误的提示。

EN

回答 1

Stack Overflow用户

发布于 2015-01-15 00:32:44

如果url请求在本地网络中,请检查主机设备中是否设置了url ip (智能手机、平板电脑的 hosts 设置,无论您用来测试什么)

警局。要在安卓系统中编辑主机设置设备,您可以使用此应用程序https://play.google.com/store/apps/details?id=com.nilhcem.hostseditor

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25384440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档