Xamarin的RestSharp for Android没有给出任何回复

时间:2014-03-13 17:44:27

标签: c# asp.net-web-api xamarin restsharp xamarin-studio

我目前正在尝试使用Mono for android,此时我已在以下网址安装了基于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;

    }

}

以下摘录使用上述代码。 (请注意,电子邮件已经过URL编码)。

public IEnumerable<PartnershipRecords> GetItemFromApi(string email, string phoneNumber)
    {

        var request = new RestRequest ();
        request.Method = Method.GET;
        request.AddParameter ("email", email);
        request.AddParameter ("phone", phoneNumber);
        var items = new RequestBrokerClass ().Execute<List<PartnershipRecords>> (request);
        return items;

    }

但是我的问题是,如果使用移动客户端进行响应,则响应始终为空,但如果使用REST客户端进行响应则不为空。

1 个答案:

答案 0 :(得分:1)

好的,我已经解决了这就是我所做的

我将以下内容添加到AndroidManifest.xml

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

瞧,服务器响应得恰到好处

相关问题