Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <curl/curl.h>
  4.  
  5. #define URL "http://192.168.1.159:8200/ctl/ContentDir"
  6.  
  7. size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream)
  8. {
  9. return fwrite(ptr,size,nmeb,stream);
  10. }
  11.  
  12. size_t read_data(void *ptr, size_t size, size_t nmeb, void *stream)
  13. {
  14. return fread(ptr,size,nmeb,stream);
  15. }
  16.  
  17. int main(char * Browse_request, char * response)
  18. {
  19.  
  20. FILE * rfp = fopen("Browse_request.xml", "r");
  21. if(!rfp) {
  22. perror("Read File Open:");
  23. }
  24.  
  25. FILE * wfp = fopen("response.xml", "w+"); //File pointer to write the soap response
  26. if(!wfp) {
  27. perror("Write File Open:");
  28. }
  29.  
  30. struct curl_slist *header = NULL;
  31. header = curl_slist_append (header, "Content-Type:text/xml; Charset=UTF-8");
  32. header = curl_slist_append (header, "SOAPAction: urn:schemas-upnp-org:service:ContentDirectory:1#Browse");
  33. header = curl_slist_append (header, "Content-Length:0");
  34.  
  35. CURL *curl;
  36. CURLcode res;
  37.  
  38. curl = curl_easy_init();
  39. if(curl) {
  40. curl_easy_setopt(curl, CURLOPT_URL, URL);
  41. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  42. curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data); //Reads xml file to be sent via POST operation
  43. curl_easy_setopt(curl, CURLOPT_READDATA, rfp);
  44. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); //Gets data to be written to file
  45. curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfp); //Writes result to file
  46. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
  47. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)-1);
  48.  
  49. curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);
  50. res = curl_easy_perform(curl);
  51.  
  52. curl_easy_cleanup(curl);
  53.  
  54. return 0;
  55. }
  56.  
  57. }
  58.  
  59. curl -v -o response.xml -H "Content-Type: text/xml; Charset="UTF-8"" -H "SOAPAction: "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"" -d @Browse_request.xml -X POST http://192.168.1.159:8200/ctl/ContentDir
  60.  
  61. <?xml version = "1.0" encoding="utf-8"?>
  62. <s:Envelope
  63. xmlns:s = "http://schemas.xmlsoap.org/soap/envelope/"
  64. s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  65. <s:Body>
  66. <u:Browse xmlns:u="urn:schemas-upnp-org:Service:ContentDirectory:1">
  67. <ObjectID>0</ObjectID>
  68. <BrowseFlag>BrowseDirectChildren</BrowseFlag>
  69. <Filter>*</Filter>
  70. <StartingIndex>1</StartingIndex>
  71. <RequestedCount>5</RequestedCount>
  72. <SortCriteria></SortCriteria>
  73. </u:Browse>
  74. </s:Body>
  75. </s:Envelope>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement