简体   繁体   中英

How to pass parameter to Post URL C#

My code :

  string postData = "'Country+Code':'US'&'Start+Date':'2018-01-01'&'End+Date':'2018-07-02'";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
request.Headers["Authorization"] = "Bearer " + accessToken;
var response = (HttpWebResponse)request.GetResponse();

I am getting 404 not found error :

I guess problem in Post data so i tride :

//string postData = "'Country Code':'US'&'Start Date':'2018-01-01'&'End Date':'2018-07-02'";
// string postData = "Country Code:'US':1&Start Date:'2018-01-01'&End Date:'2018-07-02'";

But still got error : 404 not found , finding correct way ?

If http status you receiving as 404 (Method Not Found), there are several possibilities for such error :

  1. Ensure service hosted
  2. Url Incorrect
  3. If in case url correct then the ensure the service host as POST method. If its hosted as PUT & if you are calling it as POST then you may receive such error.
  4. If all above case you have verified , cross verify whether you are sending the expected input data as per contract.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM