Back to Problem Solutions forum
Hi
Im trying to solve problem 176 "Say 100"
Here is my code:
#include <stdio.h>
#include <curl/curl.h>
int main()
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://codeabbey.sourceforge.net/say-100.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "X21+/FziHBxzqmEjYA/eWjU3");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
I cant understand what Im doing wrong, but on each run of programm, i get response: "error: No token found"
P.S. Im not asking for solution, but for advice.
Sorry, if my question is a bit stupid. Its my first time, then Im working with request.
Your question is fine, don't worry.
I think the format you need to use is: "token: X21+/FziHBxzqmEjYA/eWjU3"; you need to include the "token : " part.
I tried, but didnt help. Same message: "error: No token found"
If you're on Windows, you could try to use a tool like Fiddler2 to see what is going on during the communication. Similar "http-sniffing" tools exist for Linux or any other platform. That should help you see what is going on when your program runs.
Is there an easier way? Because I downloaded Fiddler2 and you know, there are a lot of unnecessary things and I think it will take a while me to understand where should I click to get useful information and fix the problem.
Unnecessary things? Fiddler should let you see the messages being exchanged between your PC and the server. Just click on the "raw" tab to see exactly what's being sent and received.
If that's too complicated, you can try some other library or a different language. C++ is not the web-friendliest language to do those problems in.
So, I should run Fiddler, open "raw" tab and then run my programm, and I will see what is being sent and received, right?
Well, I found raw tab, but then I run my program, there is no new session(my session) added in Fiddler, so I cant see any info of it. What should I do?
I used cURL
Try using the format "token=X21+/FziHBxzqmEjYA/eWjU3" with CURLOPT_POSTFIELDS
I also had the line curl _ easy _ setopt(curl,CURLOPT_POST,1);
Thanks, this form of token "token=X21+/FziHBxzqmEjYA/eWjU3" works.
Well, another problem. I get secret number from server. My next request should be in form?:
curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, "token=nXdWhRyYNbdpG8Vf1+KN9DQx");
curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, 100-secret_number);
or:
curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, "token=nXdWhRyYNbdpG8Vf1+KN9DQx");
curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, "answer=" 100-secret_number);
or how should it looks like?
If your secret is 74, "token=nXdWhRyYNbdpG8Vf1+KN9DQx&answer=26"
I`ll try, thank you.