1
Reply

calling url with its credentials and want to pass the file

durgam kavyasri

durgam kavyasri

Nov 6 2017 5:07 AM
155
Hi Sir,
 
 
I want to call an post method api in the .net service and api has username and password, and also i want to send the file to that api it gives the json data as response. 
api is:http://192.168.60.22:8023/mdrf/category/getSheetData 
how to pass credentials and file to that api to get the result. 
 
I tried like this but it show an error. 
public JsonResult callingurl ()
{
string file = @"E:\maharashtra.xls";
string url = "http://192.168.60.22:8023/mdrf/category/getSheetData";
using (var client = new WebClient { UseDefaultCredentials = true })
{
 client.Headers.Add(HttpRequestHeader.ContentType, "application/json; charset=utf-8");
 byte[] result = client.UploadFile(url, file);
 responseAsString = Encoding.Default.GetString(result);
 }
 
error:The remote server returned an error: (401) Unauthorized. 
 

Answers (1)