Skip to main content
Participating Frequently
November 29, 2024
Question

How to send http request in Adobe Acrobat SDK Plugin using C++

  • November 29, 2024
  • 2 replies
  • 1143 views

Hello everyone.

I'm developing a simple Adobe Acrobat SDK Plugin(I started this plugin from `Sample/BasicPlugin` project). I added new menu item and custom dialog for this plugin but I faced an issue. I can't send http request to my api host. But the code works well on Windows Desktop Application project. Below is the code to send request.

 

HINTERNET hSession = InternetOpenA("MyCustomAPIPlugin", 0, NULL, NULL, 0);
if (!hSession) {
	lastError =  GetLastError();
	return;
}

HINTERNET hConnect = InternetConnectA(hSession, "api.mycustom.dev",
	0, 0, 0, INTERNET_SERVICE_HTTP,
	0, 1);
if (!hConnect) {
	lastError = GetLastError();
	return;
}

HINTERNET hFile = HttpOpenRequestA(hConnect, "GET", "/api/cases",
"HTTP/1.0", 0, 0, INTERNET_FLAG_EXISTING_CONNECT, 1);
if (!hFile) {
	lastError = GetLastError();
	return;
}

char headers[] = "X-Api-Key: 0000-00000-00000-00000";

BOOL bRet = HttpAddRequestHeadersA(hFile, headers, static_cast<DWORD>(strlen(headers)),
	HTTP_ADDREQ_FLAG_ADD_IF_NEW);
if (!bRet) {
	lastError = GetLastError();
	return;
}
 bRet = HttpSendRequestA(hFile,
	0, 0, 0, 0);
///***** In plugin, this value is FALSE but in windows desktop application project, it's TRUE.*****
 if (!bRet) {
	 lastError = GetLastError();
	 return;
 }

 

 

This topic has been closed for replies.

2 replies

AODA_Developer
Inspiring
November 29, 2024

Hi,

I'm not sure if this would work for you, but we use cURL to send simple request-response messages from our Acrobat plugin to our server and back. 

I set up a simple function to handle the transaction with the result from the server returned as a JSON string:

#include <curl/curl.h>
#include <string>

static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
    ((string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}


/* ************************
 *
 * cURLreq
 *
 * Sends a cURL request
 *
 * ************************/
string cURLreq (string action, string accessKey, string licenseKey, string domain) {
  CURL     * curl;
  CURLcode   res;
  string     readBuffer;
  string     accRequest;

  accRequest = string("https://<yourDomainHere>/?my_action=") + action + string("&access_key=") + accessKey + string("&license_key=") + licenseKey + string("&registered_domain=") + domain + string("&item_reference=AODATool");

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, accRequest.c_str());
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    DLog(@"Result = %s", readBuffer.c_str());
  }

  return readBuffer;
}

 Not sure if this helps in your situation, but thought I'd put it out there in case anyone needs it.

Participating Frequently
November 29, 2024

As I mentioned in the description, the code is working well on Sample Windows Desktop Application Project. So I thought this issue is related to secuirty or permission for the plugin. Anyway, I'll try your code.

Thom Parker
Community Expert
Community Expert
November 29, 2024

What error code is being reported?

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
November 29, 2024

lastError is 12029

Participating Frequently
November 29, 2024

Error "12029" is a WinHTTP error code that indicates that a socket connection failed because encrypted communication couldn't be established