سؤال

I am currently experimenting with Mono for android at the moment I have a Rest based service installed at the following URL

http://localhost:8080//api/mobileclient?email=aakpenyi3%40yahoo.com&phone=80604456789

The server is IIS8.0 and service is built using asp.net web API.

When I make a request using Curi or any of the Plugin based Rest Clients. All is well and the response comes as expected

However I like to use this in a Mobile client

I have the following code using 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;

    }

}

and the following excerpt using the above code. (Please note that email has been URL encoded).

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;

    }

However my problem is that Response is always empty if made using the Mobile client but not empty if made using a REST Client.

هل كانت مفيدة؟

المحلول

OK I got it fixed here is what i did

I added the following to the AndroidManifest.xml

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

And voila, server responds appropriately

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top