2

postman demo

I used the following code to call the web service, but it didn't work. I have used postman to test successfully. Here is the demo.

3
  • $body = @{ "access_token"="24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329", "image"="base64", "language_type"="CHN_ENG", "probability"="true", "detect_direction"="true" } $header = @{ "Content-Type"="application/x-www-form-urlencoded" } Invoke-RestMethod -Uri "aip.baidubce.com/rest/2.0/ocr/v1/general_basic" -Method 'Post' -Body $body -Headers $header
    – tianyi
    May 4, 2019 at 7:11
  • My code can't be used, need to be modified, thanks in advance
    – tianyi
    May 4, 2019 at 7:12
  • Don't post code snippets in comments; Please edit the question instead and add a minimal reproducible example and format it properly using the {} (code sample icon above the editing area).
    – JosefZ
    May 4, 2019 at 8:20

1 Answer 1

0

Try this :

$body = @{ 
"access_token" = "24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329";
"image" = "base64"; 
"language_type" = "CHN_ENG";
"probability" = "true";
"detect_direction" = "true"; 
} 
$header = @{ 
"Content-Type" = "application/x-www-form-urlencoded"
} 


$response = Invoke-RestMethod -Uri "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" -Method POST -Body $body -Headers $header  | ConvertTo-Json

$response | Out-File C:\filename.txt
16
  • Thanks for your help, now have the following tips The "=" operator is missing after the key in the hash text. At line: 9 char: 8
    – tianyi
    May 4, 2019 at 10:34
  • tip: Invoke-WebRequest -Uri "aip.baidubce.com/rest/2.0/ocr/v1/general_basic" -Method POST -Body $body -Headers $header -UseBasicParsing The "Invoke-WebRequest" item cannot be recognized as a cmdlet, function, script file, or the name of a runnable program. Please check the spelling of the name. If you include the path, make sure the path is correct and try again. Location Line: 12 characters: 18
    – tianyi
    May 4, 2019 at 10:39
  • aip.baidubce.com/rest/2.0/ocr/v1/general_basic Changed to aip.baidubce.com/rest/2.0/ocr/v1/general_basic Still prompted error
    – tianyi
    May 4, 2019 at 10:44
  • then try Invoke-RestMethod instead of Invoke-WebRequest
    – rAJ
    May 4, 2019 at 10:48
  • Same tips as before
    – tianyi
    May 4, 2019 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.