Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

c# - Watson dialog cURL conversation post request not passing form data

When making a post cURL request as below to try and continue a created conversation watson instead returns a new conversation.

curl -u "USERNAME":"PASSWORD" -X POST  --form conversation_id=CONVOID  --form client_id=CLIENTID  --form input="What type of toppings do you have?"  "https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation"

If i use the below cURL it works fine.

curl -u "USERNAME":"PASSWORD" --data "conversation_id=CONVOID&client_id=CLIENTID&input=What type of toppings do you have?" https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation

My issue being that now when trying to write a c# wrapper i'm running in to the same issue that POST requests fail to transmit their form data correctly.

What's going on ?

I either need a c# MVC equivalent to the "--data" formatting. ( currently using HttpClient.PostAsync) or to figure out what is exactly wrong with using post requests to continue conversations.

As far as i can tell i am replicating the post request in c# correctly so i don't think there are two issues. ( just one post request issue, not a cURL issue then a C# implementation issue.)

For what it's worth i have left the commands in the format i submitted them, only replacing sensitive values with BLOCKCAPITALS. If it looks like i've missed a quotation mark or curly bracket , it's because i have and may be the cause of the issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The service expects an application/x-www-form-urlencoded POST request

To do that in curl you need to use the -d parameter:

curl -u "USERNAME":"PASSWORD" -X POST 
  -d conversation_id=CONVOID 
  -d client_id=CLIENTID
  -d input="What type of toppings do you have?"
  "https://gateway.watsonplatform.net/dialog/api/v1/dialogs/DIALOGID/conversation"

-d, --data

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.

Curl documentation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...