We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
bun: 1.1.38 node: 18.17.0 ofetch: 1.4.1
I have a simple api that accepts a name and return a json response. Steps:
package main import ( "encoding/json" "fmt" "log" "net/http" ) func main() { http.HandleFunc("/hello", helloHandler) fmt.Println("Server is running on port 8080...") log.Fatal(http.ListenAndServe(":8080", nil)) } func helloHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) return } err := r.ParseForm() if err != nil { http.Error(w, "Unable to parse form data", http.StatusBadRequest) return } name := r.FormValue("name") if name == "" { http.Error(w, "Name field is required", http.StatusBadRequest) return } response := map[string]string{"hello": name} w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(response) }
go run app.go
import { ofetch } from "ofetch"; const options = { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: new URLSearchParams({ name: 'abc' }) }; ofetch('http://localhost:8080/hello', options) .then(response => console.log(response)) .catch(err => console.error(err));
It should error out.
Form encoded post requests are not working as expected and erroring out(400).
I tried using simple fetch and things were working as expected.
const options = { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: new URLSearchParams({ name: 'abc' }) }; fetch('http://localhost:8080/hello', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Even curl was working:
curl --request POST http://localhost:8080/hello --header 'Content-Type: application/x-www-form-urlencoded' --data name=abc
FetchError: [POST] "http://localhost:8080/hello": 400 Bad Request
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Environment
bun: 1.1.38
node: 18.17.0
ofetch: 1.4.1
Reproduction
I have a simple api that accepts a name and return a json response.
Steps:
go run app.go
It should error out.
Describe the bug
Form encoded post requests are not working as expected and erroring out(400).
Additional context
I tried using simple fetch and things were working as expected.
Even curl was working:
curl --request POST http://localhost:8080/hello --header 'Content-Type: application/x-www-form-urlencoded' --data name=abc
Logs
FetchError: [POST] "http://localhost:8080/hello": 400 Bad Request
The text was updated successfully, but these errors were encountered: