2014-03-13 18 views
3

我目前正在與單嘗試爲Android在我在下面的網址安裝了基於REST的服務的那一刻RestSharp在Xamarin的Android不給任何迴應

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

服務器是IIS8.0和服務使用asp.net web API構建。

當我使用Curi或任何基於插件的Rest客戶端發出請求時。一切都很好,反應之際,預計

但是我喜歡在移動客戶端使用此

我使用Xamarin的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 Client進行。

+0

你已經排除了連接問題?嘗試使用'var response = new WebClient.DownloadString(「http:// localhost:8080 // api/mobileclient?email = aakpenyi3%40yahoo.com&phone = 80604456789」)加載純文本;'' – SKall

回答

1

OK我把它固定在這裏是我做過什麼

添加以下到AndroidManifest.xml中

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

瞧,服務器適當的反應