Click here to Skip to main content
15,034,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im using lob api...how to post the json data to lob api post card

https://lob.com/docs[^]


my code is
C#
public void PostData(Employee employee)
  {
       if(employee!=null)
       {
           string url = "https://api.lob.com/v1/postcards";
string jsonData = "{ \"name\" : \"ramu\", \"from\":\"sanjeev\", \"to\":\"Rajeev\",\"front\":\"file:C:\\Users\\hb1\\Desktop\\New folder\\300.png\",\"back\":\"\",\"full_bleed\":1, \"message\":\"hi how are you man\" }";

 try
           {
               WebRequest request = WebRequest.Create(url);
                  if (request != null)
                 {
                     request.Method = "POST";
                    request.Timeout = 20000;
                   // ServicePointManager.DefaultConnectionLimit = 1000;

                request.Credentials = new NetworkCredential("*********************", "");
               System.Net.ServicePointManager.Expect100Continue = false;
                    //cookie container of previous request
                 using (Stream s = request.GetRequestStream())
                    {
                    using (StreamWriter sw = new System.IO.StreamWriter(s))
                        {
                            sw.Write(jsonData);
                      }
                  }

                   using (Stream s1 = request.GetResponse().GetResponseStream())
                     {
                     using (StreamReader sr = new StreamReader(s1))
                      {
                           string jsonResponse = sr.ReadToEnd();
                  }
                     }
                 }

           }

          catch (Exception ex)
          {
              Response.Write(ex.ToString());
          }
       }
Posted
Updated 26-Nov-14 23:10pm
v3
Comments
KaushalJB 26-Nov-14 1:25am
   
So what's the issue ?
sashkhdr 26-Nov-14 3:07am
   
error is coming;The remote server returned an error: (422) Unprocessable ,

not posting the data to webapi
Jameel VM 26-Nov-14 1:58am
   
from where you try to post? u mean ajax call ?
sashkhdr 26-Nov-14 3:07am
   
i'm posting here
using (Stream s1 = request.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s1))
{
string jsonResponse = sr.ReadToEnd();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900