|
|
#include "CRUL_server_call_httpserver.h"
|
|
|
#include <map>
|
|
|
#include <string>
|
|
|
#include <sstream>
|
|
|
#include <iostream>
|
|
|
//#define HTTP_HOST "localhost"
|
|
|
#define HTTP_POST 9293
|
|
|
size_t write_data(void* ptr, size_t size, size_t nmemb, void* stream) {
|
|
|
string data((const char*)ptr, (size_t)size * nmemb);
|
|
|
*((stringstream*)stream) << data << endl;
|
|
|
return size * nmemb;
|
|
|
}
|
|
|
string callHttpserver(string signinfoJsonString, string url) {
|
|
|
CURL* curl;
|
|
|
CURLcode res;
|
|
|
curl = curl_easy_init();
|
|
|
std::stringstream out;
|
|
|
if (curl) {
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "http");
|
|
|
struct curl_slist* headers = NULL;
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
|
|
headers = curl_slist_append(headers, "Content-Type: application/json");
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
|
|
const char* data = signinfoJsonString.c_str();
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
|
|
res = curl_easy_perform(curl);
|
|
|
if (res != 0) {
|
|
|
string errMessage = curl_easy_strerror(res);
|
|
|
}
|
|
|
printf("·µ»ØÖµ£º%d\n", res);
|
|
|
}
|
|
|
string str_json = out.str();
|
|
|
curl_easy_cleanup(curl);
|
|
|
printf("str_json===>%s\n", str_json.c_str());
|
|
|
return str_json;
|
|
|
}
|
|
|
string callFsHttpserver(string signinfoJsonString, string url) {
|
|
|
CURL* curl;
|
|
|
CURLcode res;
|
|
|
curl = curl_easy_init();
|
|
|
std::stringstream out;
|
|
|
if (curl) {
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
|
|
|
struct curl_slist* headers = NULL;
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
|
|
headers = curl_slist_append(headers, "Content-Type: application/json");
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
|
|
const char* data = signinfoJsonString.c_str();
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
|
|
res = curl_easy_perform(curl);
|
|
|
if (res != 0) {
|
|
|
string errMessage = curl_easy_strerror(res);
|
|
|
}
|
|
|
printf("·µ»ØÖµ£º%d\n", res);
|
|
|
}
|
|
|
string str_json = out.str();
|
|
|
curl_easy_cleanup(curl);
|
|
|
printf("str_json===>%s\n", str_json.c_str());
|
|
|
return str_json;
|
|
|
}
|
|
|
//gfpoappÕýʽ 192.168.0.184²âÊÔ
|
|
|
string callHttpserver2(string signinfoJsonString) {
|
|
|
CURL* curl;
|
|
|
CURLcode res;
|
|
|
std::stringstream out;
|
|
|
curl = curl_easy_init();
|
|
|
if (curl) {
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "http://gfpoapp:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_CHINT_ELECTRIC&receiverParty=&receiverService=&interface=SIO_BOM_PLM_ASYN&interfaceNamespace=urn%3Achintelectric.com%3Axi%3Aplm");
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "http");
|
|
|
struct curl_slist* headers = NULL;
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
|
|
headers = curl_slist_append(headers, "Content-Type: application/xml"); //c2hwb2RldjpzYXBAMjAxOQ==²âÊÔ
|
|
|
headers = curl_slist_append(headers, "Authorization: Basic c2hwbG06c2FwQDIwMTk="); //c2hwbG06c2FwQDIwMTk=Õýʽ
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
|
|
const char* data = signinfoJsonString.c_str();
|
|
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
|
|
res = curl_easy_perform(curl);
|
|
|
if (res != 0) {
|
|
|
string errMessage = curl_easy_strerror(res);
|
|
|
}
|
|
|
printf("·µ»ØÖµ£º%d\n", res);
|
|
|
}
|
|
|
string str_json = out.str();
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
|
printf("str_json===>%s\n", str_json.c_str());
|
|
|
return str_json;
|
|
|
}
|
|
|
|
|
|
string callHttpGet(string url) {
|
|
|
void* curl = curl_easy_init();
|
|
|
// ÉèÖÃURL
|
|
|
std::stringstream out;
|
|
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
|
// ÉèÖýÓÊÕÊý¾ÝµÄ´¦Àíº¯ÊýºÍ´æ·Å±äÁ¿
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
|
|
|
|
|
// Ö´ÐÐHTTP GET²Ù×÷
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
if (res != CURLE_OK) {
|
|
|
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
|
|
}
|
|
|
|
|
|
// ½ÓÊÜÊý¾Ý´æ·ÅÔÚoutÖУ¬Êä³öÖ®
|
|
|
//cout << out.str() << endl;
|
|
|
string str_json = out.str();
|
|
|
curl_easy_cleanup(curl);
|
|
|
printf("str_json===>%s\n", str_json.c_str());
|
|
|
return str_json;
|
|
|
}
|