Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Nov 29, 2024 Nov 29, 2024

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;
 }

 

 

TOPICS
Acrobat SDK and JavaScript , Windows
547
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2024 Nov 29, 2024

What error code is being reported?

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 29, 2024

lastError is 12029

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 29, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2024 Nov 29, 2024

I use the CInternetSession class for HTTP, which is just a wrapper for the functions in your code.   The only real difference I see between your code and mine (logically speaking), are the URL of course, and the INTERNET_FLAG_EXISTING_CONNECT flag.  

Have you tried not using this flag? and/or using a different URL?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 29, 2024

As I mentioned before, the above code is working well on desktop application project. It means the url and flag is right, isn't it? This issue is not related to security or permission?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2024 Nov 29, 2024

There could very well be a security issue. Acrobat is very touchy about outside access.  Particularly when in protected mode.  So absolutely make sure the security settings are all turned off for the initial development. That said, I've never had an issue with HTTP (from a plug-in) regardless of Acrobat security. Which is why I was wondering about that flag. Could be that Acrobat doesn't allow something related to it. 

Here  is a shortened version of the code I use.   I haven't mapped all the function arguments between your code and mine, so there are probably other differences than just that flag.  

 

CInternetSession *pSession = new CInternetSession(_T("xxxx"),1,0,0,0,INTERNET_FLAG_DONT_CACHE);

CHttpFile *pFile = NULL;
CHttpConnection *pConn = pSession->GetHttpConnection(m_strDomain);
CHttpFile *pFile = pConn->OpenRequest(CHttpConnection::HTTP_VERB_GET,strURLTarget,0,1,0,0,INTERNET_FLAG_DONT_CACHE );
if(pFile->SendRequest(strHeaders))
{
	DWORD dwStat;
	pFile->QueryInfoStatusCode(dwStat);
	nRtn = static_cast<int>(dwStat);
	ULONGLONG nLen;
	BYTE* pData = (BYTE*)malloc(1024);
	while (nLen = pFile->Read(pData, 1023)) {
		pData[nLen] = 0;
		strRslt += (LPCSTR)pData;
	}
	free(pData);
}
else
{// Error Condition
}
pFile->Close();
pConn->Close();
pSession->Close();
delete pFile;
delete pConn;
delete pSession;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 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. What's your opinion? I don't need any permission to send request to any api host?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 29, 2024 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 29, 2024

Could you please guide me how to use cURL library for Adobe Acrobat SDK Plugin Development?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 29, 2024

I downloaded curl-8.11.0_4-win64-mingw.zip file and I found curl/curl.h but I can't find libcurl.dll file. Where should I download this file?

 

gabriella38414278dt43_0-1732904706161.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 29, 2024 Nov 29, 2024

Sorry, I'm not sure I can help you there. We develop for the macOS platform, not Windows, so I'm not sure how you pull in your dlls. In Xcode, it's pretty much automatic.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 29, 2024 Nov 29, 2024
LATEST

okay. anyway, thanks for your help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines