0

我在 c 编程中使用 curl 从我的 wsdl 服务中获取响应。

size_t write_data(void *ptr, size_t size, size_t count, void *stream)
{
      /* ptr - your string variable.
      stream - data chuck you received */

     printf("%.*s", size, (char*)stream);
}
int GET_FILE1(char *buffer,char *filename)
{
    CURL *curl;
    CURLcode res;
    struct curl_slist *headers = NULL;
    FILE *out_fd = (FILE *) 0;
    char errorbuf[300] = "",tmpbuff[128]="";
    char errmsg[256];
    int Timeout=120;   //Default timeout is = 2 mins
    int buffer_size = 0;
    char urlbuff[256]="";
    char mstr[10240];

    memset(urlbuff,0,sizeof(urlbuff));
        memset(tmpbuff,0,sizeof(tmpbuff));
    buffer_size = strlen(buffer);


    strcpy(tmpbuff,"http://10.10.1.182:8080/services/Application?wsdl");

    tmpbuff[strlen(tmpbuff)]='\0';
    curl = curl_easy_init();
    if(curl)
    {
        //printf("\nBUFFER:\n%s\n", buffer);
        //printf("\nbuffer_size:%d\n",buffer_size);
        //printf("\nDownloading %s file...\n", filename);
        out_fd = fopen (filename, "w");
        curl_easy_setopt(curl, CURLOPT_FILE, out_fd);
        printf("%s:Sign-In Request\n", __func__);
        headers = curl_slist_append(headers, "Content-type:application/soap+xml; charset=utf-8; action=\"http://wsdlclass.wsdlcreat.sims.com/userloginMethod\"");
        //sprintf(urlbuff,"%s?op=GetServerTime","http://119.82.117.10/clientDemo/GetServerTime.asmx");
        //sprintf(urlbuff,"%s?op=UpdatePaymentDetails",tmpbuff);
        //printf("URL:%s\n",urlbuff);
        curl_easy_setopt(curl, CURLOPT_URL, tmpbuff);
        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
        //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);


        curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
        curl_easy_setopt(curl, CURLOPT_WRITEHEADER, 0L);

        //curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_header);


        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);



        curl_easy_setopt(curl, CURLOPT_WRITEDATA, mstr);


        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, buffer_size);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buffer);

        //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        //curl_easy_setopt(curl, CURLOPT_TIMEOUT, Timeout);
        //curl_easy_setopt(curl, CURLOPT_ERRORBUFFER,errmsg);

        printf("The Server%s:Performing Transaction.....\n",__func__);
        res = curl_easy_perform(curl);
        printf("res=after culreasey perform%d\n",res);
        curl_slist_free_all(headers);
        curl_easy_cleanup(curl);
        printf("\nerrorbuf:%s\n",errmsg);
        fclose(out_fd);
        if(CURLE_OK != res)
        {
            puts("error occured is\n" );
            //ppp_close();
            return -1;
        }
    }

    return 0;
}

我已经使用上面的代码来显示输出响应,我得到了一些其他数据的响应。

<itemPrice>0.0</itemPrice><lastName xsi:nil="  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12857    0 12857    0     0   8801      0 --:--:--  0:00:01 --:--:--  8801true"/><loginStatusId>0</loginStatusId>

错误:显示输出 XML,其中包含以下文本

% Total % Received % Xferd 平均速度 时间 时间 当前 Dload 上传总花费 左速度 100 12857 0 12857 0 0 8801 0 --:--:-- 0:00:01 --:--:--

请有人帮我摆脱这个错误。谢谢。

4

0 回答 0