I've been using Mathematica to progress through the problems of codeabbey.com, and I've picked up the first of "interactive" problems (Problem #176 - Say 100), which is sort of an introductory problem to communicating with a server via POST requests, a completely new topic to me.

I am supposed to make a POST to request to the problem ("game") server with the supplied token and I should get back a response with a random number up to 100.

So, I try with the following request

requestWithToken = 
   "http://codeabbey-games.atwebpages.com/say-100.php", <|
    Method -> "POST", CharacterEncoding -> "ASCII", 
    "Body" -> "token: <my_personal_token_goes_here>"|>]

and I get back a request object with a 200 status code, which means I have successfully communicated with the server, and a text response that says

error: Content-type (text/plain;charset=utf-8) do not match data
format (text/plain)!

What am I to make of this response? That the server expects utf-8 or that it expects plain text and I'm sending utf-8? Whatever I've tried at CharacterEncoding (e.g, None, "ANSI", "UTF-8") doesn't alter the response I get. So, can anyone help me make sense of the response and form a correct request?

  • $\begingroup$ Try "ContentType"->"text/plain". $\endgroup$
    – Matariki
    Apr 17, 2022 at 1:39
  • $\begingroup$ Tried it, but it didn't work. I get the same response from the server $\endgroup$ Apr 18, 2022 at 8:17

1 Answer 1


Well, in the rare case it helps anyone, I realised, after solving the same problem using curl, that it was a case of malformed command. What I should have written instead was

problemURL = "http://codeabbey-games.atwebpages.com/say-100.php";
sessionToken = "nU5YKQ37Fra0GyiL/uFL2Tc0";
   problemURL, <|"Method" -> "POST", 
    "Body" -> {"token" -> sessionToken}|>]]["Body"]

which would result in a string like "answer: x" where x a random integer between 1 and 99

and at the next step I would just have to POST again using

URLRead[HTTPRequest[problemURL, <|"Method" -> "POST", 
     "Body" -> {"token" -> sessionToken, 
       "answer" -> 100 - x}|>]]["Body"] 

so both the token and the answer are passed as arguments in the "Body" list. Nice to finally get it. Have a good one!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.