【问题标题】:use a restful web service in windows phone 8.1在 windows phone 8.1 中使用 restful web 服务
【发布时间】:2014-06-18 20:09:14
【问题描述】:

热烈的问候。 我想知道如何在我的 windows phone 8.1 应用程序中使用使用 java 开发的 restful web 服务(http://192.168.10.113:8087/cisms/mobilews/)。我正在使用带有 c# 的 Visual Studio 2013。

更新:我的网络服务 (http://192.168.10.152:8087/cisms/mobilews/login/userNameCheck?userName=supervisor) 中的一种 GET 方法存在另一个问题。当我根据给定的 URL 创建以下示例代码时,它引发了另一个异常。

static string UserValidation()
    {
        HttpWebRequest req = WebRequest.Create("http://192.168.10.113:8087/cisms/mobilews/login/userNameCheck?userName=supervisor") as HttpWebRequest;
        string result = null;
        using (HttpWebResponse resp = req.GetResponse()  as HttpWebResponse)
        {
            StreamReader reader =
                new StreamReader(resp.GetResponseStream());
            result = reader.ReadToEnd();
        }
        return result;
    }

http://rest.elkstein.org/2008/02/using-rest-in-c-sharp.html

下面给出了例外情况

'System.Net.HttpWebRequest' does not contain a definition for 'GetResponse' and no
 extension method 'GetResponse' accepting a first argument of type 
'System.Net.HttpWebRequest' could be found (are you missing a using directive or an 
assembly reference?)

注意:我只在 Windows_Phone_application 中收到此错误;不在 Desktop_Application 中。

如果有人能进一步帮助我,那就太好了

提前致谢 塞巴斯蒂安

【问题讨论】:

    标签: rest windows-phone-8


    【解决方案1】:

    RestSharp 允许您轻松请求 Web 服务。或者你可以使用HttpClient

    【讨论】:

    • 我尝试过httpwebrequest的方式,但很少有例外。我使用的一种网络服务方法是 GET;网址如下...192.168.10.152:8087/cisms/mobilews/login/… 当我点击以下网址时,rest.elkstein.org/2008/02/using-rest-in-c-sharp.html;它引发了以下异常“System.Net.HttpWebRequest”不包含“GetResponse”的定义如果您能进一步帮助我,那就太好了
    • 我不在我的工作电脑前,但也许你可以试试这样:HttpWebResponse resp = ((await req.GetResponseAsync()) as HttpWebResponse)
    • 我已经尝试过了,但得到了同样的例外。我注意到此错误仅出现在 windows_phone_application 中,而不出现在 Desktop_application 中。
    • 尝试使用 sy httpClient.GetASync() 而不是 WebRequest
    • 如果时间允许,你能给我看一个示例吗,因为我无法将 System.Net.Http.dll is 添加到我的 .net 4.5 应用程序中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多