How to send cURL/API requests in C# with webRequest Class Multible Commands -
this question has answer here:
i need send server:
curl https://api.placetel.de/api/getrouting.xml \ -d 'api_key=xxxxxxxxxxxxxxxxxxx' \ -d 'number=068111111xxx'
if try:
webrequest request = webrequest.create("https://api.placetel.de/api/getrouting.xml"); request.method = "post"; string postdata = "api_key=xxxxxxxxxxxxxxx number=0685123xxxxxx"; byte[] bytearray = encoding.utf8.getbytes(postdata); stream datastream = request.getrequeststream(); datastream.write(bytearray, 0, bytearray.length); datastream.close(); webresponse response = request.getresponse(); datastream = response.getresponsestream(); streamreader reader = new streamreader(datastream); string responsefromserver = reader.readtoend(); listbox1.items.add(responsefromserver);
i login error - api not right becouse programm sends api + number= in "one line"
the question how can send in 2 commands`? try strings postdata & postdata1 aso - doesn´t work
like:
string postdata1 = "\nnumber=068567909000"; byte[] bytearray1 = encoding.utf8.getbytes(postdata1);
add contenttype
, separate each parameter ampersand:
request.contenttype = "application/x-www-form-urlencoded"; var postdata = "api_key=xxxxxxxxxxxxxxx"; postdata += "&number=0685123xxxxxx";
Comments
Post a Comment