Can someone please help me with the correct way to set certain parameters in httr::POST()
function?
I have been trying to convert the following http request
command in vain.
POST https://germanywestcentral.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-invoice:analyze?api-version=2022-06-30-preview HTTP/1.1
Host: germanywestcentral.api.cognitive.microsoft.com
Content-Type: application/json
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••
{
"urlSource": "string" #I changed this one to accommodate raw image
}
The R
command I'm trying is as follows.
URL<-"https://germanywestcentral.api.cognitive.microsoft.com/formrecognizer/documentModels/prebuilt-invoice:analyze?api-version=2022-06-30-preview&stringIndexType=textElements"
img_png <- png::readPNG("./images/2.png", native = TRUE, info = TRUE)
binary_img <- as.raw(img_png)
POST(URL,add_headers(.headers=c(`Ocp-Apim-Subscription-Key`= "***",
Host= "germanywestcentral.api.cognitive.microsoft.com",
`Content-Type`="image/png")), # I changed the content type to the required one
body=binary_img,
config(http_version=1.1),
verbose())
I get the following response.
-> POST /formrecognizer/v2.1/prebuilt/invoice/analyze HTTP/1.0
-> Host: germanywestcentral.api.cognitive.microsoft.com
-> User-Agent: libcurl/7.79.1 r-curl/4.3.2 httr/1.4.3
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> Ocp-Apim-Subscription-Key: ******
-> Content-Type: image/png
-> Content-Length: 1882232
->
>>
>>
>>
<- HTTP/1.1 400 Bad Request
<- Keep-Alive: true
<- Content-Length: 170
<- Content-Type: application/json; charset=utf-8
<- x-envoy-upstream-service-time: 280
<- apim-request-id: 34b7c286-ccf9-45b1-88dd-bfc48ca99f4e
<- Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
<- x-content-type-options: nosniff
<- Date: Mon, 22 Aug 2022 19:25:03 GMT
<- Connection: close
<-
Response [https://germanywestcentral.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/invoice/analyze]
Date: 2022-08-22 19:25
Status: 400
Content-Type: application/json; charset=utf-8
Size: 170 B
Thanks in advance.