The OnResponse() function *must* return some integer. It can be any value, since the result of this function isn't used currently, but it should probably be non-zero, assuming the function was successful.
The heap error should not be happening, since the memory pointed to by *response should not be corrupted. Did you change any project settings or otherwise do anything to that memory location, by chance?
Also, if you take a look at this code:
int onResponse (int event, char *response, int length) {
char buf[500]; // or the maxlength of your response;
for (int i=0; i<length; i++)
buf = response;
buf[length] = '\0';
// Now use buf to finish your action
Looking at your code line by line, you're declaring a new character buffer 500 bytes long. The for loop, however, doesn't make sense. You're setting the same pointer over and over (from 0 to length-1). If you wanted to get at each character in the string, you'd need to write your for loop like so:
for (int i=0;i<length;i++)
buf[i]=response[i];
But, this is unnecessary. If you're going to do this this way, just leave off the for loop and do a
buf=response;
Next, consider what happens if length is greater than 500, or whatever size buffer you declared? You will overflow your buffer and a crash will follow.
This is why my simple solution calls for slamming a NULL character into the byte at length. Since, by definition, the response buffer will be at least that long...
I hope this helps!