Rectangle 27 2

Even though, I have been using 400 to represent logical errors also, I have to say that returning 400 is wrong in this case because of the way the spec reads. Here is why i think so, the logical error could be that a relationship with another entity was failing or not satisfied and making changes to the other entity could cause the same exact to pass later. Like trying to (completely hypothetical) add an employee as a member of a department when that employee does not exist (logical error). Adding employee as member request could fail because employee does not exist. But the same exact request could pass after the employee has been added to the system.

Just my 2 cents ... We need lawyers & judges to interpret the language in the RFC these days :)

HTTP 400 (bad request) for logical error, not malformed request syntax...

http http-status-codes http-status-code-400
Rectangle 27 1

Checking git settings: Executing command (CWD): git config color.ui
OK
Checking http connectivity to packagist: Downloading http://packagist.org/packages.json
FAIL
[Composer\Downloader\TransportException] The "http://packagist.org/packages.json" file could not be downloaded (HTTP/1.1 400 Bad Request)

php - Composer HTTP 400 Bad request when downloading Laravel - Stack O...

php laravel composer-php packagist
Rectangle 27 2

I maintain some current IPN programs and it looks to me like your method of reading data is not likely to obtain the full response from PayPal. TCP data are sent in packets, and PayPal response are not sent as a single buffer, so it is actually very unlikely that a single read would actually contain as many bytes as possible up to the 1,024 bytes requested.

In order to implement in your own code, you would have to loop and append to a variable what you read until reaching the EOF.

I think that I can see your mistake now. Your fgets statement reads only one line of the response at a time because it stops reading when length is reached or when a newline is reached, whichever comes first. The line you are looking for is in the body of Pay Pal's response, not in the first few lines (header, etc.). Yet your else statement is included within the loop. Therefore your else statement is always executed once the first line of the header is received from PayPal.

I suggest two changes. Move the failure code after the loop, because failure isn't actually known for sure until the EOF has been reached.

The other change I suggest is to use strpos instead of strcmp. Although the paypal response body contains just the single word verified, there is a good chance that CR or LF or both will be part of that line which fgets reads. And so strcmp will fail. You can use the condition strpos ($res, "VERIFIED") !== false in place of your existing condition (and the same change for checking if INVALID was received.

This is some possible code that might work (I can't test this code in your situation, and code that is untested can never be sure of working). Please just take this code as a suggestion, not as a literal answer:

// Post request back to PayPal for validation
    fputs ($fp, $header . $data);
    while (!feof($fp)) {                     // While not EOF
        $res = fgets ($fp, 1024);              // Get the acknowledgement response
        if (strpos ($res, "VERIFIED") !== false)  {  // Response is VERIFIED
            $response = 'verified';
            // Notification protocol is complete, OK to process notification contents

            // Possible processing steps for a payment might include the following:

            // Check that the payment_status is Completed
            // Check that receiver_email is your Primary PayPal email
            // Check that payment_amount/payment_currency are correct
            // Process payment
            break;
        }
        else if (strpos ($res, "INVALID") !== false)  { // Response is INVALID
            $response = 'invalid';
            break;
        } 
    }
    fclose ($fp);  //close file pointer 
    if ($response == 'verified')
        return true;
    else if ($response == 'invalid') {
            return false;
        }
    else { // no else statement is actually needed here,
           // since the previous conditions both return
        throw new Exception("Unexpected response from PayPal: $res");
        return false;
    }

PayPal IPN: HTTP/1.1 400 Bad Request - Stack Overflow

paypal paypal-sandbox paypal-ipn
Rectangle 27 4

Catch exp As WebException

    'Read the real response from the server
    Dim sResponse As String = New StreamReader(exp.Response.GetResponseStream()).ReadToEnd

.Net HttpWebRequest.GetResponse() raises exception when http status co...

.net httpwebrequest
Rectangle 27 4

Catch exp As WebException

    'Read the real response from the server
    Dim sResponse As String = New StreamReader(exp.Response.GetResponseStream()).ReadToEnd

.Net HttpWebRequest.GetResponse() raises exception when http status co...

.net httpwebrequest
Rectangle 27 7

I was also getting this issue also however none of the above worked for me as I was using a custom binding (for BinaryXML) after an long time digging I found the answer here :-

As am using a customBinding, the maxReceivedMessageSize has to be set on the httpTransport element under the binding element in the web.config:

<httpsTransport maxReceivedMessageSize="4194304" />

Thanks a lot :-)

c# - Large WCF web service request failing with (400) HTTP Bad Request...

c# .net wcf web-services
Rectangle 27 7

I was also getting this issue also however none of the above worked for me as I was using a custom binding (for BinaryXML) after an long time digging I found the answer here :-

As am using a customBinding, the maxReceivedMessageSize has to be set on the httpTransport element under the binding element in the web.config:

<httpsTransport maxReceivedMessageSize="4194304" />

Thanks a lot :-)

c# - Large WCF web service request failing with (400) HTTP Bad Request...

c# .net wcf web-services
Rectangle 27 2

After a lot of test, it's working. I need to configure the bindings section in webHttpBinding rather than basicHttpBinding, but I don't know why.

<bindings>
    <webHttpBinding>
        <binding name="TransportSecurity">
            <security mode="Transport">
                <transport clientCredentialType="None" />
            </security>
        </binding>
    </webHttpBinding>
</bindings>

c# - .net WCF GET HTTPS 400 Bad Request but woks fine with Http - Stac...

c# .net wcf ssl https
Rectangle 27 13

Edit. This is above and beyond the HTTP specifications. If we simply return a 201 after a POST, the browser back button behaves badly.

Note that Web Services requests (which do NOT respond to a browser) follow the standard completely and do NOT redirect after post.

Now -- hey presto! -- the back button works.

Since your code doesn't show redirect-after-post, it appeared as though you didn't realize that your application had to do this. "IE, Firefox and Chrome all fail to redirect to the new resource" indicates that you're not doing the redirect in your application.

If you're saying that the correct browser reaction to a 201 response is not to try and GET the url given back in the Location header, and that the server should send a redirect instead of a 201, then it does answer the question in part, but the specs don't suggest that 3xx are valid responses.

@Giraffe: the specs don't suggest that 3xx are valid responses. Correct. It's a usability thing that's above and beyond the standard.

asp.net mvc - What is the correct response to an HTTP POST request? - ...

asp.net-mvc http http-headers
Rectangle 27 2

I am using rails to extract the same authentication token cookie from stage.amee.com/auth as mentioned above. it took a bit of experimentation before I created and customised the correct request object that returned a 200 OK, with the authtoken as a cookie. i haven't found an effective method of reading the request object or I would post exactly what it looks like. here is my ruby code from the app's controller

#define parameters
uri=URI.parse('http://stage.amee.com')
@path = '/auth'
@login_details = 'username=your_username&password=your_password'
@headers = {'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'}

#create request object
req = Net::HTTP.new(uri.host, uri.port)

#send the request using post, defining the path, body and headers
resp, data = req.post(@path, @login_details, @headers)

#print response details to console
puts "response code = " << resp.code
puts "response inspect = " << resp.inspect
resp.each do |key, val| 
  puts "response header key : " + key + " = " + val 
end 
puts "data: " + data

asp.net - How to get JSON back from HTTP POST Request (to another doma...

asp.net api post request
Rectangle 27 1

In my case, it was not working even after trying all solutions and setting all limits to max. In last I found out that a Microsoft IIS filtering module Url Scan 3.1 was installed on IIS/website, which have it's own limit to reject incoming requests based on content size and return "404 Not found page".

%windir%\System32\inetsrv\urlscan\UrlScan.ini
MaxAllowedContentLength

c# - Large WCF web service request failing with (400) HTTP Bad Request...

c# .net wcf web-services
Rectangle 27 1

In my case, it was not working even after trying all solutions and setting all limits to max. In last I found out that a Microsoft IIS filtering module Url Scan 3.1 was installed on IIS/website, which have it's own limit to reject incoming requests based on content size and return "404 Not found page".

%windir%\System32\inetsrv\urlscan\UrlScan.ini
MaxAllowedContentLength

c# - Large WCF web service request failing with (400) HTTP Bad Request...

c# .net wcf web-services
Rectangle 27 0

I would suggest not attempting to read the Request.InputStream during Application_Start - it's used for initialising the application. Accessing the Request object from within Application_Start results in an exception "Request is not available in this context."

Application_BeginRequest

asp.net - First request fails with HTTP 400 (Bad Request) after readin...

asp.net http iis
Rectangle 27 0

Even though, I have been using 400 to represent logical errors also, I have to say that returning 400 is wrong in this case because of the way the spec reads. Here is why i think so, the logical error could be that a relationship with another entity was failing or not satisfied and making changes to the other entity could cause the same exact to pass later. Like trying to (completely hypothetical) add an employee as a member of a department when that employee does not exist (logical error). Adding employee as member request could fail because employee does not exist. But the same exact request could pass after the employee has been added to the system.

Just my 2 cents ... We need lawyers & judges to interpret the language in the RFC these days :)

HTTP 400 (bad request) for logical error, not malformed request syntax...

http http-status-codes http-status-code-400
Rectangle 27 0

I am using rails to extract the same authentication token cookie from stage.amee.com/auth as mentioned above. it took a bit of experimentation before I created and customised the correct request object that returned a 200 OK, with the authtoken as a cookie. i haven't found an effective method of reading the request object or I would post exactly what it looks like. here is my ruby code from the app's controller

#define parameters
uri=URI.parse('http://stage.amee.com')
@path = '/auth'
@login_details = 'username=your_username&password=your_password'
@headers = {'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'}

#create request object
req = Net::HTTP.new(uri.host, uri.port)

#send the request using post, defining the path, body and headers
resp, data = req.post(@path, @login_details, @headers)

#print response details to console
puts "response code = " << resp.code
puts "response inspect = " << resp.inspect
resp.each do |key, val| 
  puts "response header key : " + key + " = " + val 
end 
puts "data: " + data

asp.net - How to get JSON back from HTTP POST Request (to another doma...

asp.net api post request
Rectangle 27 0

Total guess: try and use blogContext.Posts.Create() rather than new Post(). That way, your original object will be created by EF rather than be a naked CLR object.

asp.net mvc - EF Code First not returning object as DynamicProxies unt...

asp.net-mvc entity-framework asp.net-mvc-3 ef-code-first code-first
Rectangle 27 0

It was no problem with raspberry or mono or Web Api itself. The self hosted service was initialized with the base URL http://localhost. The strange thing is, the service is only available via localhost, but not via the according IP address!!!

So what I've done now is, I substituted localhost with the IP address of my Pi and it works perfectly. Now the service is only accessible via the IP?!

I still have no clue why it makes a difference, but obviously it does.

asp.net web api - Self hosted Wep Api on my Respbarry Pi leads to HTTP...

asp.net-web-api mono raspberry-pi self-hosting
Rectangle 27 0

var oAuthConsumerKey = "key";
          var oAuthConsumerSecret =     "key";
              var oAuthUrl = "https://api.twitter.com/oauth2/token";
         var screenname = "nouman_engineer";

 // Do the Authenticate
                 var authHeaderFormat = "Basic {0}";

                       var authHeader = string.Format(authHeaderFormat,
Convert.ToBase64String(Encoding.UTF8.GetBytes(Uri.EscapeDataString(oAuthConsumerKey) + ":" +
Uri.EscapeDataString((oAuthConsumerSecret)))
                         ));

    var postBody = "grant_type=client_credentials";

   HttpWebRequest authRequest =    (HttpWebRequest)WebRequest.Create(oAuthUrl);
    authRequest.Headers.Add("Authorization", authHeader);
    authRequest.Method = "POST";
authRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
authRequest.AutomaticDecompression = DecompressionMethods.GZip |    DecompressionMethods.Deflate;

    using (Stream stream = authRequest.GetRequestStream())
  {
   byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
  }

  authRequest.Headers.Add("Accept-Encoding", "gzip");

    WebResponse authResponse = authRequest.GetResponse();
   // deserialize into an object
     TwitAuthenticateResponse twitAuthResponse;
       using (authResponse)
       {
        using (var reader = new         StreamReader(authResponse.GetResponseStream())) {
      JavaScriptSerializer js = new JavaScriptSerializer();
     var objectText = reader.ReadToEnd();
    twitAuthResponse =     JsonConvert.DeserializeObject<TwitAuthenticateResponse>(objectText);
}
  }

     // Do the timeline
     var timelineFormat =          "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=  {0}&include_rts=1&exclude_replies=1&count=5";
      var timelineUrl = string.Format(timelineFormat, screenname);
         HttpWebRequest timeLineRequest =   (HttpWebRequest)WebRequest.Create(timelineUrl);
    var timelineHeaderFormat = "{0} {1}";
   timeLineRequest.Headers.Add("Authorization",    string.Format(timelineHeaderFormat, twitAuthResponse.token_type,     twitAuthResponse.access_token));
    timeLineRequest.Method = "Get";
    WebResponse timeLineResponse = timeLineRequest.GetResponse();
      var timeLineJson = string.Empty;
     using (timeLineResponse)
      {
 using (var reader = new          StreamReader(timeLineResponse.GetResponseStream()))
    {
       timeLineJson = reader.ReadToEnd();
   }
      }
      }

and do something by your self and please comment only links and helping meterials donot talk only

c# - Http web request The remote server returned an error: (400) Bad R...

c# asp.net .net twitter twitter-oauth
Rectangle 27 0

It took a few hours after that for it to actually then start working though (I think it should have been within about 30 seconds but took longer than that for some reason).

asp.net - GetListItems "request failed with HTTP status 401: Unauthori...

asp.net sharepoint-2010 impersonation