• 0

C# Posting to URL Help "/


Question

Hey guys, Just wondering if you can help me with my project.
 
I'm currently attempting to post to a url. I'll provide as much information as possible below without giving out my actual API url out to people since it's client based.
 
So here is what I'm trying to do, For instance here is my api url.

https://test-to-show-you.com/API/Authentication

I've tried adding the post to the url but that doesn't work because it gives no response for example.

https://test-to-show-you.com/API/Authentication?payload=user%3Dtestusername%2Cpassword%3Dtestpassword

But when using postman google chrome app, I can post to this fine, obviously not in the url though.
 
and this is a POST method with Content-Type: application/x-www-form-urlencoded
 
Here is what I'm trying to post to the url "payload=user%3Dtestusername%2Cpassword%3Dtestpassword"
 
Before going any further I'd just like to say it needs to be exactly like this otherwise you get no response from the server so it needs the %3D and %2C in the post method for some strange reason.
 
Here is what I've currently got coded into my application.

var tasks = new List<Task<string>>();
for (int i = 0; i < accoutList.Count(); i++)
{
int g = i;
var postParameters = new NameValueCollection();
try
{
Accounts ac = accoutList[i];
tasks.Add(Task.Factory.StartNew(() => { return GetWebResponse("https://test-to-show-you.com/API/Authenticate", g); }));
}
 
catch
{
 
}
} 

So I'm just really stuck here on how to post that exactly to the url inhand. Would appreciate some support into this.

Link to comment
https://www.neowin.net/forum/topic/1247586-c-posting-to-url-help/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

 

 You pass parameters in the URL during an HTTP GET, not a POST. Try creating a WebRequest with that URL, and specifying POST.

WebRequest request = WebRequest.Create(url);
request.Method = "POST";
// Fill in other request HTTP headers

 

it's actually a little more complicated than that I have already justified the method is to POST.

 

               var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                httpWebRequest.CookieContainer = new CookieContainer();
This topic is now closed to further replies.