curl-library
Re: How to capture Error message from the Server
Date: Tue, 17 May 2016 21:24:10 +0000
Hi Ray,
Say, I need to read a file and it has “This is a test.” in it.
I issue a GET for an object in the cloud. My callback is called with “This is a test.” in the buffer. I saved it into a local file. All is fine.
Now, if someone deleted the object. I did not know. I issue a GET. My callback gets:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>smC1842A51E22A05000000000000A386410000000100003J7M3CMY9CMULJKG6Q</Key><RequestId>B09B6836031219A8</RequestId><HostId>GIxwOGJB8DMKoIxYcqNkRDL/a1rcrPyg7hmMx+UNNtvUVgaOILdjCMe/ntfo/+bIxWG1D5ws7SU=</HostId></Error>
In my callback I did not know that this is an error message. I just save it in my local file. Toss my buffer away. Now I get an error return from libcurl with some http error.
So, the question is how do I know my callback has been called with the Server’s extended error message, so that I can save it and not write it to file and toss the buffer away ..
Thanks.
Colin
On 5/17/16, 4:06 PM, "curl-library on behalf of Ray Satiro via curl-library" <curl-library-bounces_at_cool.haxx.se on behalf of curl-library_at_cool.haxx.se> wrote:
>On 5/17/2016 4:42 PM, Colin Ngam wrote:
>> Yes, I understand that part after I get the content.
>>
>> In a GET situation my callback gets called by libcurl with data:
>> 1st Call – I save the data.
>> 2nd Call – I save the data.
>> 3rd Call – I save the data.
>> Done. Good.
>>
>> Now, if the Server has an error after the 2nd call, the 3rd call comes
>> in, I do not know that it is an error message, I save and toss buffer.
>> Save means write to file. Now I get an error condition status.
>>
>> What I am doing right now is that at each of the Call above, I compare
>> the buffer for "<?xml version=“ and if it compares, I save it off to
>> an error buffer just in case.
>
>Please do not top post it makes the conversation harder to follow [1].
>
>I'm not sure I understand what you mean. To copy and paste from another
>topic I just replied to: The write function is passed as much data as
>available when it's called [2]. It will likely be called multiple times,
>each time with a piece of the reply. It's up to your callback to append
>those pieces. Take a look at the getinmemory example [3].
>
>Once you have received the reply body in full then you can pass it to an
>XML parser. If you are using a library like libxml2 it is possible to
>use something like xmlParseChunk [4] instead to pass each chunk from the
>write callback as it is received.
>
>
>[1]: https://urldefense.proofpoint.com/v2/url?u=https-3A__curl.haxx.se_mail_etiquette.html-23Do-5FNot-5FTop-5FPost&d=CwIGaQ&c=8S5idjlO_n28Ko3lg6lskTMwneSC-WqZ5EBTEEvDlkg&r=GgZxxOrjo7rUSi2a3aY7DXfeWcIXQ3Xn4a7ByYeR4wA&m=j6mf5IM4yebCXegKbj7LWFnozBECCHx46vqYlU72iyQ&s=k8mjvTwz51Bs7QQSR3eM1Q69zvlrBQehCRZXBKywW9E&e=
>[2]: https://urldefense.proofpoint.com/v2/url?u=https-3A__curl.haxx.se_libcurl_c_CURLOPT-5FWRITEFUNCTION.html&d=CwIGaQ&c=8S5idjlO_n28Ko3lg6lskTMwneSC-WqZ5EBTEEvDlkg&r=GgZxxOrjo7rUSi2a3aY7DXfeWcIXQ3Xn4a7ByYeR4wA&m=j6mf5IM4yebCXegKbj7LWFnozBECCHx46vqYlU72iyQ&s=jO7Hhk-GGC9KkgyGdZo6MucnB69lCDLqtO_0RveWmho&e=
>[3]: https://urldefense.proofpoint.com/v2/url?u=https-3A__curl.haxx.se_libcurl_c_getinmemory.html&d=CwIGaQ&c=8S5idjlO_n28Ko3lg6lskTMwneSC-WqZ5EBTEEvDlkg&r=GgZxxOrjo7rUSi2a3aY7DXfeWcIXQ3Xn4a7ByYeR4wA&m=j6mf5IM4yebCXegKbj7LWFnozBECCHx46vqYlU72iyQ&s=0fAbQwD08s__inITDpbiobxSMEx_tTDIHK_ecVf6OMQ&e=
>[4]: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.xmlsoft.org_examples_parse4.c&d=CwIGaQ&c=8S5idjlO_n28Ko3lg6lskTMwneSC-WqZ5EBTEEvDlkg&r=GgZxxOrjo7rUSi2a3aY7DXfeWcIXQ3Xn4a7ByYeR4wA&m=j6mf5IM4yebCXegKbj7LWFnozBECCHx46vqYlU72iyQ&s=4MxfFsoerXdEcZQk01aOYTkv0NFhBHvh446efHPC6-w&e=
>
>-------------------------------------------------------------------
>List admin: https://urldefense.proofpoint.com/v2/url?u=https-3A__cool.haxx.se_list_listinfo_curl-2Dlibrary&d=CwIGaQ&c=8S5idjlO_n28Ko3lg6lskTMwneSC-WqZ5EBTEEvDlkg&r=GgZxxOrjo7rUSi2a3aY7DXfeWcIXQ3Xn4a7ByYeR4wA&m=j6mf5IM4yebCXegKbj7LWFnozBECCHx46vqYlU72iyQ&s=NMqlxfDO_HoajZIDP1rBH_tk8S9as_P0NofDE-O6pao&e=
>Etiquette: https://urldefense.proofpoint.com/v2/url?u=https-3A__curl.haxx.se_mail_etiquette.html&d=CwIGaQ&c=8S5idjlO_n28Ko3lg6lskTMwneSC-WqZ5EBTEEvDlkg&r=GgZxxOrjo7rUSi2a3aY7DXfeWcIXQ3Xn4a7ByYeR4wA&m=j6mf5IM4yebCXegKbj7LWFnozBECCHx46vqYlU72iyQ&s=_H8Yr1rdVljO_-vXw16mnDjrb5c9u1ANUV06D4nPaNc&e=
----------------------------------------------------------------------
The information contained in this transmission may be confidential. Any disclosure, copying, or further distribution of confidential information is not permitted unless such privilege is explicitly granted in writing by Quantum. Quantum reserves the right to have electronic communications, including email and attachments, sent across its networks filtered through anti virus and spam software programs and retain such messages in order to comply with applicable data security and retention requirements. Quantum is not responsible for the proper and complete transmission of the substance of this communication or for any delay in its receipt.
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-05-17