question

gaffer.tape avatar image
gaffer.tape asked

RegisterPlayFabUser - Bad Request via http POST

Hi all,

Just started using PlayFab recently for a small experimental game I'm building.

Right now I'm just trying to register a new player with PlayFab via a website.

The data seems to be valid JSON formatted (at least Visual Studio reports so). Everything is fine and dandy, however I already get a 400, Bad Request response.

Not sure what's causing this, there isn't much to work on since there are no error details and info on raw http POST methods is pretty sparse in the docs.

Thank you.

I'm using this code -

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

This is for Title ID 3D22, correct? Normally, there is always an ErrorDetails in the response. However, looking in out logs, what I'm seeing is that your requests are coming in with a Content-Type of "application/x-www-form-urlencoded":

Message: Returning error for invalid request Content-Type: application/x-www-form-urlencoded URL: http://3d22.playfabapi.com/Client/RegisterPlayFabUser

This seems odd, given that you appear to be setting the ContentType to "application/json" in the code above (which would be correct). However "application/x-www-form-urlencoded" is the default if no ContentType is specified in WebRequest, so I have to assume your ContentType is somehow being lost, though I can't see how from that code. Can you try putting a breakpoint into the Write, to see what's actually being sent?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gaffer.tape avatar image
gaffer.tape answered

Hi Brendan, thanks for that.

I'm not sure why the content-type is wrong, but I managed to solve it by wrapping the response in a Try/Catch. Seems it was just the password being too short, though I admit I thought PlayFab would return a custom error code for that instead of 400.

 

Thanks again...not sure why it works...but it does!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

There actually is an error for this. I just re-tested, and if the password is too short, this is the response:

{
  "code": 400,
  "status": "BadRequest",
  "error": "InvalidParams",
  "errorCode": 1000,
  "errorMessage": "Invalid input parameters",
  "errorDetails": {
    "Password": [
      "Password must be between 6 and 100 characters."
    ]
  }
}

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gaffer.tape avatar image
gaffer.tape answered

Thanks, I'm seeing it now. Probably something went wrong in the network when I was testing it out which caused a truncated response.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.