bashcurlvisual-studio-app-center

Curl post coming back wit HTTP Error 411. The request must be chunked or have a content length


I am trying to upload and distribute builds from App Center. But I can see mu curl commands are throwing HTTP 411 error for POST requests.

API_URL="https://api.appcenter.ms/v0.1/apps/$TEAM_APP"
AUTH="X-API-Token: $API_TOKEN"
ACCEPT_JSON="Accept: application/json"
request_url="$API_URL/uploads/releases"
upload_json=$(curl -s -X POST -H "Content-Type: application/json" -H "$ACCEPT_JSON" -H "$AUTH" "$request_url")

and this is the error I can see in my ci pipeline:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
1s
13  <HTML><HEAD><TITLE>Length Required</TITLE>
1s
14  <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
1s
15  <BODY><h2>Length Required</h2>
1s
16  <hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
1s
17  </BODY></HTML>

I don't have much idea on how to use curl, any one can help me in figuring out what is it I am doing wrong?


Solution

  • The error code 411 means lacking the header of Content-Type, can try this

    upload_json=$(curl -s -X POST -H "Content-Type: application/json" -H "$ACCEPT_JSON" -H "$AUTH" -H "content-length: 0" "$request_url")

    Details can refer this.

    or

    upload_json=$(curl -s -X POST -H "Content-Type: application/json" -H "$ACCEPT_JSON" -H "$AUTH" -> data '' "$request_url")