Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 针对Android的Xamarin中的RestSharp未给出任何响应_C#_Asp.net Web Api_Xamarin_Restsharp_Xamarin Studio - Fatal编程技术网

C# 针对Android的Xamarin中的RestSharp未给出任何响应

C# 针对Android的Xamarin中的RestSharp未给出任何响应,c#,asp.net-web-api,xamarin,restsharp,xamarin-studio,C#,Asp.net Web Api,Xamarin,Restsharp,Xamarin Studio,我目前正在试用android版的Mono,现在我在下面的URL上安装了一个基于Rest的服务 http://localhost:8080//api/mobileclient?email=aakpenyi3%40yahoo.com&phone=80604456789 服务器是IIS8.0,服务是使用asp.net web API构建的 当我使用Curi或任何基于插件的Rest客户端发出请求时。一切顺利,反应如期 然而,我喜欢在移动客户端中使用它 我有以下使用Xamarin for And

我目前正在试用android版的Mono,现在我在下面的URL上安装了一个基于Rest的服务

http://localhost:8080//api/mobileclient?email=aakpenyi3%40yahoo.com&phone=80604456789
服务器是IIS8.0,服务是使用asp.net web API构建的

当我使用Curi或任何基于插件的Rest客户端发出请求时。一切顺利,反应如期

然而,我喜欢在移动客户端中使用它

我有以下使用Xamarin for Android的代码

    public class RequestBrokerClass
{
    const string baseUrl = "http://partnerens.com/api/mobileclient/";


    public T Execute<T>(RestRequest request) where T : new()
    {
        var client = new RestClient ();
        client.BaseUrl = baseUrl;
        var response = client.Execute<T> (request);
        if (response.ErrorException != null) {
            const string message = "Error contacting partnerens servers";
            var exception = new ApplicationException (message, response.ErrorException);
            throw exception;
        }
        return response.Data;

    }

}
公共类RequestBrokerClass
{
常量字符串baseUrl=”http://partnerens.com/api/mobileclient/";
public T Execute(RestRequest请求),其中T:new()
{
var client=newrestclient();
client.BaseUrl=BaseUrl;
var response=client.Execute(请求);
if(response.ErrorException!=null){
const string message=“联系partnerens服务器时出错”;
var exception=新的ApplicationException(消息、响应.ErrorException);
抛出异常;
}
返回响应数据;
}
}
下面是使用上述代码的摘录。(请注意,电子邮件已被URL编码)

public IEnumerable GetItemFromApi(字符串电子邮件、字符串电话号码)
{
var request=new RestRequest();
request.Method=Method.GET;
request.AddParameter(“电子邮件”,电子邮件);
request.AddParameter(“电话”,电话号码);
var items=newrequestbrokerclass().Execute(请求);
退货项目;
}

然而,我的问题是,如果使用移动客户端,响应总是空的,但是如果使用REST客户端,响应不是空的。

好的,我在这里修复了它,这就是我所做的

我在AndroidManifest.xml中添加了以下内容

    <uses-permission android:name="android.permission.INTERNET" />


瞧,服务器响应正确

您排除了连接问题了吗?尝试使用“var response=new WebClient.DownloadString(“);”加载纯文本
    <uses-permission android:name="android.permission.INTERNET" />