hoppscotch / hoppscotch

Open source API development ecosystem - https://hoppscotch.io (open-source alternative to Postman, Insomnia)
https://hoppscotch.io
MIT License
65.59k stars 4.55k forks source link

Failed to execute 'setRequestHeader' on 'XMLHttpRequest': '' is not a valid HTTP header field name. #649

Closed codeasashu closed 4 years ago

codeasashu commented 4 years ago

Describe the bug Unable to set application/x-www-form-urlencoded as Content-Type header. Setting this header gives me HTTP status code 500, however cUrl is working for the same.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Home'
  2. Enter 'application/x-www-form-urlencoded' in 'Content-Type' header section
  3. Send the POST request to https://httpbin.org/post
  4. Response status gives following error: "Failed to execute 'setRequestHeader' on 'XMLHttpRequest': '' is not a valid HTTP header field name.", with HTTP status code 500.

Expected behavior The response should be same as the output of cUrl curl -XPOST -H 'Content-Type: application/x-www-form-urlencoded' http://httpbin.org/post

{
  "args": {},
  "data": "",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org",
    "Referer": "",
    "User-Agent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
    "X-Amzn-Trace-Id": "Root=1-5e6090d9-0b751e5ac119b94d699aa887"
  },
  "json": null,
  "origin": "182.76.138.139",
  "url": "http://httpbin.org/post"
}

Desktop (please complete the following information):

Additional context I am using https://postwoman.io/ to test this.

liyasthomas commented 4 years ago

I couldn't reproduce the issue.

Set up 1: Set Content-Type in request section itself

Request

postwoman io__method=POST url=https___httpbin org path=_post contentType=application_x-www-form-urlencoded

Response

postwoman io__method=POST url=https___httpbin org path=_post contentType=application_x-www-form-urlencoded (3)

As you can see, response Content-Type is application/x-www-form-urlencoded


Set up 2: Set Content-Type in Headers section itself

Request

postwoman io__method=POST url=https___httpbin org path=_post contentType=application_x-www-form-urlencoded (2)

Response

postwoman io__method=POST url=https___httpbin org path=_post contentType=application_x-www-form-urlencoded (1)

As you can see, response Content-Type is application/x-www-form-urlencoded

codeasashu commented 4 years ago

Ok weird, it works now. Don't know why it happended but seems to be fixed now. I will make sure to check for anything else I might have done to cause this issue. Thanks for taking your time to reply.