c# - POST to my localhost on port 5587 -
i want able write code interacts app running on computer listening on port 5587.
static void main(string[] args) { httppost("http://localhost:5587", "/send/?username=testingname&password=testingpw"); } public static string httppost(string uri, string parameters) { system.net.webrequest req = system.net.webrequest.create(uri); req.proxy = webrequest.defaultwebproxy; //add these, we're doing post req.contenttype = "application/x-www-form-urlencoded"; req.method = "post"; //we need count how many bytes we're sending. params should name=value& byte[] bytes = system.text.encoding.ascii.getbytes(parameters); req.contentlength = bytes.length; system.io.stream os = req.getrequeststream(); os.write(bytes, 0, bytes.length); //push out there os.close(); system.net.webresponse resp = req.getresponse(); if (resp == null) return null; system.io.streamreader sr = new system.io.streamreader(resp.getresponsestream()); resp.close(); return sr.readtoend().trim(); }
when read specs on app, says:
1) post request should be:
http://host:port/send/? username=user& password=pw& to=destination& bcc=bccdestination& subject=messagesubject
2) , post data should be:
message=messagebody
3) also, post request returns uuid of message in queue. uuid used later checking status of messages in queue.
how might change code pull off 3 things there need including getting response id can save later?
edit:
there screen shot of output need looks versus output putting out.
the query string parameters should part of uri string, , message needs set in request body
call this
string uuid = httppost("http://localhost:5587/send/?username=user&password=pw&to=destination&bcc=bccdestination&subject=messagesubject", "message=hi there"); console.writeline(uuid); console.readline();
change last 2 lines of httppost method to
string uuid = sr.readtoend().trim(); resp.close(); return uuid;
of course need change parameters values valid
Comments
Post a Comment