• 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.
  • Posts

    • It is silly there is no simple way to check whether this profile has been activated. CFRs are normal, but trying to even hide the fact if it's on / off seems silly, especially for something so user-facing. Surely Microsoft is "proud" of their engineering efforts on this one and ought to display it somwhere in the GUI.
    • Many Linux distros are not known for excellent battery life, so I'm not sure that is the best example. A more apt example may be Apple, but Apple's CPUs are simply far more efficient than Intel & AMD at single-threaded tasks like these, so "boosting" is not as power-hungry and less heat-inducing. Not to mention Apple will hardly engage P-cores for basic UI tasks; they use a pretty complicated QoS scheme to only activate P-cores for more serious workloads like HTML / JS execution or decompression or application launch. Microsoft is (smartly) doing it for launch, but also for UI tasks, which is the more nonsensical part: why ... do Windows 11's UIs need modern CPUs to boost? It should load so quickly that there's not even time for the CPU to boost.
    • I've not seen any controlled testing and, judging by Microsoft's mentality, within a year, they'll have added so much more bloat, it'll undo any perceptible latency benefit and we'll have boosted the CPU clocks for nothing.
    • It depends: heat soak is a thing. Initially on cold boot-up, the heatsinks & heatpipes are at ambient temp. After heatsinks & heatpipes warm up (through normal usage), they don't immediately cool to ambient temp when the load goes away. So their baseline is higher and the trigger point for fans is much less stress. Add a few more CPU spikes → it's too hot to stay at the same fan RPM → fans get triggered to start up up much sooner / get triggered to ramp much more quickly.
    • Can LibreOffice just shut up and worry about themselves and stop comparing themselves? Do we see Microsoft complaining about euro office?
  • Recent Achievements

    • One Year In
      slackerzz earned a badge
      One Year In
    • One Year In
      highriskpaym earned a badge
      One Year In
    • One Month Later
      highriskpaym earned a badge
      One Month Later
    • Week One Done
      highriskpaym earned a badge
      Week One Done
    • Week One Done
      FBSPL earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      501
    2. 2
      PsYcHoKiLLa
      198
    3. 3
      +Edouard
      156
    4. 4
      Steven P.
      84
    5. 5
      ATLien_0
      71
  • Tell a friend

    Love Neowin? Tell a friend!