TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Saravanan Ponnusamy
364
4.5k
1.1m
c# Convert curl request into http request?
Apr 12 2018 7:02 AM
Reference:
curl https://api.lob.com/v1/postcards \
-u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \
-d "description=Demo Postcard job" \
-d "to[name]=Harry Zhang" \
-d "to[address_line1]=185 Berry St" \
-d "to[address_line2]=# 6100" \
-d "to[address_city]=San Francisco" \
-d "to[address_state]=CA" \
-d "to[address_zip]=94107" \
-d "to[address_country]=US" \
-d "from[name]=Leore Avidar" \
-d "from[address_line1]=185 Berry St" \
-d "from[address_line2]=# 6100" \
-d "from[address_city]=San Francisco" \
-d "from[address_state]=CA" \
-d "from[address_zip]=94107" \
-d "from[address_country]=US" \
-d "front=tmpl_b846a20859ae11a" \
-d "back=tmpl_01b0d396a10c268" \
-d "merge_variables[name]=Harry"
im trying convert the above CURL into C# HTTPRequest
WebRequest req = WebRequest.Create(@"https://api.lob.com/v1/postcards?description=Demo Postcard job&to[name]=Harry Zhang&to[address_line1]=185 Berry St&to[address_line2]=no 6100&to[address_city]=San Francisco&to[address_state]=CA&to[address_zip]=94107&to[address_country]=US&from[name]=Leore Avidar&from[address_line1]=185 Berry St&from[address_line2]=no 6100&from[address_city=San Francisco&from[address_state]=CA&from[address_zip]=94107&from[address_country]=US&front=tmpl_a5bb07d8301c90e&back=tmpl_efeba684a3e3c3b&merge_variables[name]=saravanan");
//WebRequest req = WebRequest.Create(@"https://api.lob.com/v1/addresses/adr_58f75c708b98d2fc");
req.Method = "POST";
req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("test_48d2bbf75401d119bfae5526:"));
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
Stream zStream;
StreamReader zStreamReader;
string zszReturn = "";
zStream = resp.GetResponseStream();
zStreamReader = new StreamReader(zStream, Encoding.UTF8);
zszReturn = zStreamReader.ReadToEnd();
but it throws 422 exception... i dont wheather the url which i passing is in correct formate or not..
Reply
Answers (
1
)
Retrieving data of user transaction in MVC
Simple question please help