Curl syntax simulation in Java

I have a curl syntax in .sh file. I need to run the curl sytnax or curl command in Java replicating the same syntax, but I am facing problem in replicating the same. $AUTH_OPTION="--basic -u testuser:testpwd" $HTTP_METHOD=POST $FILE_OPTION="-d @$INPUT_FILE" $CONTENT_TYPE="application/xml" $ACCEPT_TYPE="application/xml" echo curl -o response.txt -w %{http_code} -k -v $AUTH_OPTION -X $HTTP_METHOD $FILE_OPTION -H \"Content-Type: $CONTENT_TYPE\" -H \"Accept: $ACCEPT_TYPE\" I have the corresponding Java code as: StringBuffer curlCmd=new StringBuffer(); curlCmd.append("curl -o response.txt"); curlCmd.append(WHITE_SPACE); curlCmd.append("-w %{http_code}"); curlCmd.append("-k -v -u testuser:testpwd"); curlCmd.append(WHITE_SPACE); curlCmd.append("-X POST"); curlCmd.append(WHITE_SPACE); curlCmd.append("-d @/test/xyz/xml" ); curlCmd.append(WHITE_SPACE); curlCmd.append("-H"+"Content-type: application/xml"); curlCmd.append(WHITE_SPACE); curlCmd.append("-H"+" Accept: application/xml"); curlCmd.append(WHITE_SPACE); This does not seems to work: its not simulating the same behaviour of .sh curl syntax. Can any one help me to sort out this issue? output curl -o response.txt -w %{http_code} -k -v -u testuser:testpwd -X POST -d @/path/xyz.xml -H "Content-Type: application/xml" -H "Accept: application/xml" the problem is xml is not getting accessed properly
i have used --basic also but that alos does not seems to work

以上就是Curl syntax simulation in Java的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准