Comments (1)
You don't specify the method curl should use, so it defaults to GET
. Add -X POST
to the curl command. Also, the --data-raw
flag isn't supported, but since you're not using @ in the message body, you can just use --data
.
That would give you a curl command of:
curl -X POST 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule' \
-H 'Connection: keep-alive' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'Origin: http://fanyi.youdao.com' \
-H 'Referer: http://fanyi.youdao.com/' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cookie: SESSION_FROM_COOKIE=www.google.com; [email protected]; UM_distinctid=17697740fd4170-04dc0273ef4b3b-163b6152-384000-17697740fd5ad9; JSESSIONID=aaakvUkIMF4LE_Ut7nBAx; OUTFOX_SEARCH_USER_ID_NCOO=1853585491.4869733; ___rl__test__cookies=1608921911154' \
--data 'i=representative&from=AUTO&to=AUTO&smartresult=dict&client=fanyideskweb&salt=16089219111571&sign=a112f16df706f6ed109f690c3cfe5193<s=1608921911157&bv=351bfce8c0555a52efc8c9f4762d3359&doctype=json&version=2.1&keyfrom=fanyi.web&action=FY_BY_REALTlME' \
--compressed \
--insecure
And the resultant output would be
require 'net/http'
require 'uri'
require 'openssl'
uri = URI.parse("http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/x-www-form-urlencoded; charset=UTF-8"
request["Connection"] = "keep-alive"
request["Pragma"] = "no-cache"
request["Cache-Control"] = "no-cache"
request["Accept"] = "application/json, text/javascript, */*; q=0.01"
request["X-Requested-With"] = "XMLHttpRequest"
request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
request["Origin"] = "http://fanyi.youdao.com"
request["Referer"] = "http://fanyi.youdao.com/"
request["Accept-Language"] = "en-US,en;q=0.9"
request["Cookie"] = "SESSION_FROM_COOKIE=www.google.com; [email protected]; UM_distinctid=17697740fd4170-04dc0273ef4b3b-163b6152-384000-17697740fd5ad9; JSESSIONID=aaakvUkIMF4LE_Ut7nBAx; OUTFOX_SEARCH_USER_ID_NCOO=1853585491.4869733; ___rl__test__cookies=1608921911154"
request.set_form_data(
"action" => "FY_BY_REALTlME",
"bv" => "351bfce8c0555a52efc8c9f4762d3359",
"client" => "fanyideskweb",
"doctype" => "json",
"from" => "AUTO",
"i" => "representative",
"keyfrom" => "fanyi.web",
"lts" => "1608921911157",
"salt" => "16089219111571",
"sign" => "a112f16df706f6ed109f690c3cfe5193",
"smartresult" => "dict",
"to" => "AUTO",
"version" => "2.1",
)
req_options = {
use_ssl: uri.scheme == "https",
verify_mode: OpenSSL::SSL::VERIFY_NONE,
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
# response.code
# response.body
Is this closer to what you wanted?
from curl-to-ruby.
Related Issues (12)
- Need to add require "json" when using json HOT 1
- Add support for -i, --include HOT 1
- add support for --resolve
- Command line support
- Add support for -F HOT 2
- not handling "?" in url HOT 1
- EOFError at /registration end of file reached
- Support -k HOT 1
- Add support for -L
- Add support for -G HOT 2
- --digest not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from curl-to-ruby.