The error means the url is not correctly formed.
Do a print from each app and compare.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
One of my code is perfectly working in Asp.Net MVC 5 But when I am using some logic to call the api in Asp.Net MVC Core (6), Api is always returning an error.
Same parameters and same address is being used in both technologies but old approach is working.
Please see my Old and New Logic to call this api. and guide me to fix it.
The Api Url is :
https://pcls1.craftyclicks.co.uk/json/rapidaddress?key=mykey&include_geocode=true&&postcode=DD68AB&response=data_formatted
Asp.Net MVC 5
using (var client = new HttpClient())
{
string addressUri = WebConfigurationManager.AppSettings["addressUri"];
var uri = addressUri + postcode.Replace(" ","") + "&response=data_formatted";
var response = await client.GetAsync(uri);
string textResult = await response.Content.ReadAsStringAsync();
lObjApiRes = JsonConvert.DeserializeObject<AddressLookupViewModel>(textResult);
}
AspNet MVC Core (6)
AddressLookupViewModel? nullableApiResObj = null;
Task<Stream> streamTask = client.GetStreamAsync(uri);
nullableApiResObj = await JsonSerializer.DeserializeAsync<AddressLookupViewModel?>(await streamTask);
This approach return everything null and doesn't throw any error
I tried another solution, please see below
using (HttpClient client = new HttpClient())
{
string addressUri = Configuration["CustomSettings:AddressUri"];
string uri = addressUri + postcode.Replace(" ", "") + "&response=data_formatted";
string textResult = "";
HttpRequestMessage request = new HttpRequestMessage()
{
RequestUri = new Uri(uri),
Method = HttpMethod.Get,
};
HttpResponseMessage response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
textResult = await response.Content.ReadAsStringAsync();
}
}
The steps are simple to reproduce the case. Just create an Asp.Net MVC Core (.Net 6) project and try my code.
Please guide me to resolve the issue in a better way.
Why I am always getting this error:
textResult always return {"error_code":"0001","error_msg":"No data was found for the requested postcode."}
Thank you
The error means the url is not correctly formed.
Do a print from each app and compare.
The error means the url is not correctly formed.
Do a print from each app and compare.