locked
WebRequest changes my original url and calls get method (.net 4.5.1) RRS feed

  • Question

  • User1993069894 posted

    I have a Url that is already url encoded and a hash is generated for the encoded part. I need to get the response of this url in server side, but the problem is webrequest changes to Upper case the encoded part of the url so in the other side when api tries to rehash and check the request it fails.

    the original url string is:

    /yonlendirme.aspx?action=create&name=Deneme%20Alt%20%c4%b0%c3%a7erik%20Oturumu%202&meetingID=baa4a6b1&moderatorPW=M97f15B7113G&attendeePW=Ow2D75JE160B&voiceBridge=73079&welcome=%25%25CONFNAME%25%25%27e+ho%c5%9fgeldiniz&logoutURL=http%3a%2f%2fidollive.idolyazilim.net&checksum=5ab4fe8ddf18385ceb1e5f035f0a2259d60f1fc4&CustCode=6d3bae161a&meetingS=1425298560&meetingE=1425309390

    and after initialize using webrequest.create function it turned to:

    /yonlendirme.aspx?action=create&name=Deneme%20Alt%20%C4%B0%C3%A7erik%20Oturumu%202&meetingID=baa4a6b1&moderatorPW=M97f15B7113G&attendeePW=Ow2D75JE160B&voiceBridge=73079&welcome=%25%25CONFNAME%25%25'e+ho%C5%9Fgeldiniz&logoutURL=http:%2f%2fidollive.idolyazilim.net&checksum=5ab4fe8ddf18385ceb1e5f035f0a2259d60f1fc4&CustCode=6d3bae161a&meetingS=1425298560&meetingE=1425309390

    the change in hex parts of url (for example: Deneme%20Alt%20%c4%b0%c3%a7erik != Deneme%20Alt%20%C4%B0%C3%A7erik | or => logoutURL=http%3a%2f%2fidollive.idolyazilim.net != logoutURL=http:%2f%2fidollive.idolyazilim.net) prevent the verification phase of the app in the other api site. (please pay attention to change in http%3a changed to http: )

    so simply I want to force WebRequest to not change casing of my url or is there another library to sent http request and get response?

    Note: this behavior is only in .net 4.5 and in .net 4.0 I didn't have this problem.

    Tuesday, March 3, 2015 4:47 AM

Answers

  • User-1078840699 posted

    Hi,

    Doing this requires understanding how HTTP redirects work. When you use Response.Redirect(), you send a response (to the browser that made the request) with HTTP Status Code 302, which tells the browser where to go next. By definition, the browser will make that via a GET request, even if the original request was a POST.

    Another option is to use HTTP Status Code 307, which specifies that the browser should make the redirect request in the same way as the original request, but to prompt the user with a security warning. To do that, you would write something like this:

    public void PageLoad(object sender, EventArgs e)
    {
        // Process the post on your side   
    
        Response.Status = "307 Temporary Redirect";
        Response.AddHeader("Location", "http://example.com/page/to/post.to");
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 23, 2015 8:11 PM

All replies

  • User-1538479794 posted

    Have a look at the link

    https://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx

    Hope this could help you.

    May

    Wednesday, March 4, 2015 3:39 AM
  • User1993069894 posted

    Dear May-song Thank you for your reply, but are you understand my question? I already can send request and get response, but the problem is webrequest or maybe Uri used in it changes my Url casting and also some characters that this ıssue problems with encrypting system in the other site.

    Wednesday, March 4, 2015 5:34 AM
  • User-1910946339 posted

    Can you show your code - both sending and receiving side.

    Please don't post your entire application.  Create a small project which exhibits the problem then post the essential pieces of code such that anyone can reproduce your problem.

    Wednesday, March 4, 2015 5:27 PM
  • User-1078840699 posted

    Hi,

    Doing this requires understanding how HTTP redirects work. When you use Response.Redirect(), you send a response (to the browser that made the request) with HTTP Status Code 302, which tells the browser where to go next. By definition, the browser will make that via a GET request, even if the original request was a POST.

    Another option is to use HTTP Status Code 307, which specifies that the browser should make the redirect request in the same way as the original request, but to prompt the user with a security warning. To do that, you would write something like this:

    public void PageLoad(object sender, EventArgs e)
    {
        // Process the post on your side   
    
        Response.Status = "307 Temporary Redirect";
        Response.AddHeader("Location", "http://example.com/page/to/post.to");
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 23, 2015 8:11 PM