0

I am integrating payu to my web app. The problem is I can not request new order It returns 403 forbidden in my app but with same data I can get 200 from api doing it postman. I got token,created authorization,sent headers(authorization,content-type,content-length). Here is my post method.

 var request = (HttpWebRequest)WebRequest.Create(new Uri(Url));
        var postData = RawData;//json data

        request.Method = "POST";
        request.ContentType = ContentType;
        if (Headers != null) // add headers
        {
            foreach (var header in Headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }
        }
        var data = Encoding.UTF8.GetBytes(postData);

        request.ContentLength = data.Length;

        using (var stream = new StreamWriter(request.GetRequestStream()))
        {
            stream.Write(data);
        }


        try
        {
            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            return responseString;
        }
        catch (WebException e) 
        {
            return null;
        }
snn
  • 1
  • 3
  • Is it on purpose that you are using *data* when setting `request.ContentLength = data.Length` but then use *postData* in `stream.Write(postData);` - or did that happen by accident? (no expert here... just seeing a potential mixup) – Peter B Nov 14 '16 at 14:09
  • @PeterB while I try different methods I forgot to change postData to data.Still same situation happens.Thanks for your attention – snn Nov 17 '16 at 06:21

1 Answers1

0

Please add this line.

request.UseDefaultCredentials = true;

or you can see the complete explanation of this error here on stackoverflow.

The remote server returned an error: (403) Forbidden

Community
  • 1
  • 1