Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Bad request issue #93

Closed
nittonfemton opened this issue Feb 24, 2016 · 5 comments
Closed

400 Bad request issue #93

nittonfemton opened this issue Feb 24, 2016 · 5 comments
Assignees

Comments

@nittonfemton
Copy link

My code:

$response = Unirest\Request::post("https://textanalysis.p.mashape.com/nltk-sentence-segmentation",
  array(
    "X-Mashape-Key" => <key>,
    "Content-Type" => "application/x-www-form-urlencoded",
    "Accept" => "application/json"
  ),
  array(
    "text" => "Natural language processing (NLP) deals with the application of computational models to text or speech data. Application areas within NLP include automatic (mach
  )
);

Response:

Unirest\Response Object
(
    [code] => 400
    [raw_body] => <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>

    [body] => <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>

    [headers] => Array
        (
            [0] => HTTP/1.1 400 BAD REQUEST
            [Content-Type] => text/html
            [Date] => Wed, 24 Feb 2016 15:33:40 GMT
            [Server] => Mashape/5.0.6
            [X-RateLimit-requests-Limit] => 1000
            [X-RateLimit-requests-Remaining] => 974
            [Content-Length] => 192
            [Connection] => keep-alive
        )
)

cURL works fine:
curl -X POST --include 'https://textanalysis.p.mashape.com/spacy-named-entity-recognition-ner'
-H 'X-Mashape-Key: '
-H 'Content-Type: application/x-www-form-urlencoded'
-H 'Accept: application/json'
-d 'text=Rami Eid is studying at Stony Brook University in New York'

I thought it might be a SSL problem, so I disabled peer verification with:

Unirest\Request::verifyPeer(false);

Is there a way to see all the curl options from unirest? Or debug the request somehow?

@ahmadnassri
Copy link
Contributor

you can try using mockbin.org to debug the request easily, I suggest you try there, maybe make a bin and share it back here so we can inspect together.

@ahmadnassri ahmadnassri self-assigned this Feb 24, 2016
@nittonfemton
Copy link
Author

POSTing to mockbin gave a 200 response.

{
  "method": "POST",
  "url": "https://mockbin.org/bin/7ff87e6d-e74e-4db0-b43d-9013a2188b12?foo=baz",
  "httpVersion": "HTTP/1.1",
  "cookies": [],
  "headers": [
    {
      "name": "host",
      "value": "mockbin.org"
    },
    {
      "name": "connection",
      "value": "close"
    },
    {
      "name": "accept-encoding",
      "value": "gzip"
    },
    {
      "name": "x-forwarded-for",
      "value": "52.16.192.49, 162.158.39.52"
    },
    {
      "name": "cf-ray",
      "value": "279d41d7a58429a5-DUB"
    },
    {
      "name": "x-forwarded-proto",
      "value": "http"
    },
    {
      "name": "cf-visitor",
      "value": "{\"scheme\":\"https\"}"
    },
    {
      "name": "x-mashape-key",
      "value": "WqABxUxPjsdggsdokjsgdsjgodosjgjopsdgjopgdojpgsd"
    },
    {
      "name": "accept",
      "value": "application/json"
    },
    {
      "name": "user-agent",
      "value": "unirest-php/2.0"
    },
    {
      "name": "content-type",
      "value": "application/x-www-form-urlencoded; boundary=------------------------31bd4d8f7a22b37f"
    },
    {
      "name": "cf-connecting-ip",
      "value": "52.16.192.49"
    },
    {
      "name": "x-request-id",
      "value": "433a43df-d0e5-4828-a390-bfa6b4466dc5"
    },
    {
      "name": "x-forwarded-port",
      "value": "80"
    },
    {
      "name": "via",
      "value": "1.1 vegur"
    },
    {
      "name": "connect-time",
      "value": "2"
    },
    {
      "name": "x-request-start",
      "value": "1456338789159"
    },
    {
      "name": "total-route-time",
      "value": "0"
    },
    {
      "name": "content-length",
      "value": "197"
    }
  ],
  "queryString": [
    {
      "name": "foo",
      "value": "baz"
    }
  ],
  "postData": {
    "mimeType": "application/x-www-form-urlencoded",
    "text": "--------------------------31bd4d8f7a22b37f\r\n    Content-Disposition: form-data; name=\"text\"\r\n    \r\n    Rami Eid is studying at Stony Brook University in New York\r\n    --------------------------31bd4d8f7a22b37f--\r\n    ",
    "params": [
      {
        "name": "--------------------------31bd4d8f7a22b37f\r\n    Content-Disposition: form-data; name",
        "value": "\"text\"\r\n    \r\n    Rami Eid is studying at Stony Brook University in New York\r\n    --------------------------31bd4d8f7a22b37f--\r\n    "
      }
    ]
  },
  "headersSize": 705,
  "bodySize": 197
}

@ahmadnassri
Copy link
Contributor

indeed a serious bug here ... fixing now.

@ahmadnassri
Copy link
Contributor

this is now fixed in v3.0.0

PLEASE NOTE: v3.0.0 introduces API changes, please review the release notes and README for details

@nittonfemton
Copy link
Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants