Rahul Rai

Rahul Rai

  • 1.6k
  • 149
  • 11k

transfer mvc controller data Json format in Web Api method

May 11 2019 5:15 AM
public async Task<string> UploadImage(HttpPostedFileBase objFile, string user_id)
{
Session["imgfile"] = objFile;
Session["user_id"] = user_id;
//string anykey = string.Empty;
string responseString = string.Empty;
string name="";
string type = "";
if (objFile != null)
{
JObject payLoad = new JObject(
new JProperty("anykey",
new JObject(
new JProperty("KidYhE", 3288),
new JProperty("type", "QUERY")
),
new JProperty(objFile.FileName)
//new JProperty("password", "User Password"),
//new JProperty("token", "xxxxxx")
)
);
using (HttpClient client = new HttpClient())
{
var httpContent = new StringContent(payLoad.ToString(), Encoding.UTF8, "multipart/form-type");
using (HttpResponseMessage response = await client.PostAsync("http://192.168.0.187:8081/ImageUpload/Upload", httpContent))
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
//return JObject.Parse(responseBody);
}
}

Answers (1)