Reputation: 1
Error:
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
[DOTNET] {
[DOTNET] Connection: close
[DOTNET] Date: Fri, 21 Feb 2025 09:51:10 GMT
[DOTNET] Server: Microsoft-HTTPAPI/2.0
[DOTNET] X-Android-Received-Millis: 1740131468716
[DOTNET] X-Android-Response-Source: NETWORK 400
[DOTNET] X-Android-Selected-Protocol: http/1.1
[DOTNET] X-Android-Sent-Millis: 1740131465418
[DOTNET] Content-Length: 334
[DOTNET] Content-Type: text/html; charset=us-ascii
[DOTNET] }
Code:
public async Task<int> PostServiceint(string UR, object obj)
{
int bln = 0;
try
{
foreach (var prop in obj.GetType().GetProperties())
{
Console.WriteLine($"{prop.Name}: {prop.GetValue(obj)}");
}
HttpClientHandler handler = new HttpClientHandler
{
// ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
};
using (var client = new HttpClient(handler))
{
client.Timeout = TimeSpan.FromMinutes(10);
Console.WriteLine(obj.ToString());
var response = client.PostAsJsonAsync(UR, obj).Result;
var data = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
string JsonString = response.Content.ReadAsStringAsync().Result;
bln = Convert.ToInt32(JsonString);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return bln;
}
URL FOR WINDOWS => ("http://localhost:2824/api/" + Controller + "/" + Method)
URL FOR ANDROID=> ("http://10.0.2.2:2824/api/" + Controller + "/" + Method)
For windows it works for android it gives error posted in start
I tried playing around but no way out do comment any suggestion/answer accepted
Upvotes: 0
Views: 31