<div dir="ltr"><div dir="ltr"><div dir="ltr">Andy,<div><br></div><div>Thanks for your response. When calling lws_hdr_copy, I was using the size returned by lws_hdr_total_length and the string is empty. I figured out it has to be <span style="background-color:rgb(255,255,0)">sz + 1</span> and it worked.</div><div><br></div><div><div>case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: {</div><div>      req->status = lws_http_client_http_response(wsi);</div><div>      auto sz = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE);</div><div>      char buf[1024];</div><div>      lws_hdr_copy(wsi, buf, <span style="background-color:rgb(255,255,0)">sz</span>, WSI_TOKEN_HTTP_CONTENT_TYPE);</div><div>          printf("???????? %d %s\n", sz,  buf);</div><div>      break;</div><div>    }</div></div><div><br></div><div>Thanks,</div><div>Kun</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 12, 2019 at 10:46 AM Andy Green <<a href="mailto:andy@warmcat.com">andy@warmcat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 11/02/2019 12:36, Kun Zhao wrote:<br>
> Hi,<br>
> <br>
> For http client, how do I get response headers?<br>
<br>
At LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP you can get the server response <br>
code with<br>
<br>
status = lws_http_client_http_response(wsi);<br>
<br>
and the server's response headers with the same apis used by server-side <br>
to get the client request headers (they are parsed into the same ah <br>
struct attached to the wsi either way), eg<br>
<br>
<a href="https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n344-353" rel="noreferrer" target="_blank">https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n344-353</a><br>
<br>
<a href="https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n368-383" rel="noreferrer" target="_blank">https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n368-383</a><br>
<br>
The list of known header indexes is here<br>
<br>
<a href="https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n214-305" rel="noreferrer" target="_blank">https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n214-305</a><br>
<br>
-Andy<br>
<br>
> Thanks,<br>
> Kun<br>
> <br>
> _______________________________________________<br>
> Libwebsockets mailing list<br>
> <a href="mailto:Libwebsockets@ml.libwebsockets.org" target="_blank">Libwebsockets@ml.libwebsockets.org</a><br>
> <a href="https://libwebsockets.org/mailman/listinfo/libwebsockets" rel="noreferrer" target="_blank">https://libwebsockets.org/mailman/listinfo/libwebsockets</a><br>
> <br>
</blockquote></div>