HttpClient myClient = new HttpClient();
myClient.BaseAddress = new Uri(URL);
基地址已經在客戶端指定了它的URL。Xamarin__HttpClient__HttpResponseMessage-Content ---獲取HTML而不是JSON
var encodedObject = JsonConvert.SerializeObject(Obj);
myClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await myClient.PostAsync("test.php/yourAPI",new StringContent(encodedObject, System.Text.Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
var responseContent = response.ToString();
var responsebody = response.Content.ToString();
Stream receiveStream = response.GetResponseStream();
string responseBodyAsText = response.Content.ReadAsStringAsync().Result;
}
您是否也在控制服務器端代碼? – Nkosi
In away是!它不是公共服務器!回答你的問題 –
在很多這樣的情況下,服務器拋出一個錯誤並且默認錯誤頁面(html)。您正在呼叫的端點。它是一個web api或正常Asp.Net MVC – Nkosi