- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想发送 POST 请求到 https://parts-of-speech.info/tagger/tagger参数为“text=”和“language=”。
到目前为止,我已经尝试了三个过程:AsyncTask 中的 JsonObjectRequest、Jsoup.connect 和 HttpURLConnection,但似乎都不起作用。
这是 JsonObjectRequest 的代码:
Map<String, String> params = new HashMap();
params.put("text", "This is a text.");
params.put("language", "en");
JSONObject parameters = new JSONObject(params);
JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.POST, stringurl, parameters, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//TODO: handle success
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
//TODO: handle failure
}
});
Volley.newRequestQueue(this).add(jsonRequest);
这是轨迹:
2019-10-22 17:46:04.390 19530-19530/? I/hsulaiman.ling: Late-enabling -Xcheck:jni
2019-10-22 17:46:04.992 19530-19530/com.jwanhsulaiman.lingu W/hsulaiman.ling: JIT profile information will not be recorded: profile file does not exits.
2019-10-22 17:46:05.000 19530-19530/com.jwanhsulaiman.lingu I/chatty: uid=10082(com.jwanhsulaiman.lingu) identical 10 lines
2019-10-22 17:46:05.000 19530-19530/com.jwanhsulaiman.lingu W/hsulaiman.ling: JIT profile information will not be recorded: profile file does not exits.
2019-10-22 17:46:05.020 19530-19530/com.jwanhsulaiman.lingu I/Perf: Connecting to perf service.
2019-10-22 17:46:05.038 19530-19530/com.jwanhsulaiman.lingu I/InstantRun: starting instant run server: is main process
2019-10-22 17:46:05.337 19530-19530/com.jwanhsulaiman.lingu W/hsulaiman.ling: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-10-22 17:46:05.339 19530-19530/com.jwanhsulaiman.lingu W/hsulaiman.ling: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-10-22 17:46:05.499 19530-19530/com.jwanhsulaiman.lingu D/OpenGLRenderer: Skia GL Pipeline
2019-10-22 17:46:55.482 19530-19555/com.jwanhsulaiman.lingu I/Adreno: QUALCOMM build : 7ae04e7, Ia74c9b5270
Build Date : 09/20/18
OpenGL ES Shader Compiler Version: EV031.25.03.00
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.7.4.R1.09.00.00.453.030
Remote Branch : NONE
Reconstruct Branch : NOTHING
2019-10-22 17:46:55.483 19530-19555/com.jwanhsulaiman.lingu I/Adreno: Build Config : S L 6.0.7 AArch64
2019-10-22 17:46:55.483 19530-19555/com.jwanhsulaiman.lingu D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8998.so from current namespace instead of sphal namespace.
2019-10-22 17:46:55.474 19530-19530/com.jwanhsulaiman.lingu W/RenderThread: type=1400 audit(0.0:375092): avc: denied { search } for name="proc" dev="debugfs" ino=11046 scontext=u:r:untrusted_app:s0:c82,c256,c512,c768 tcontext=u:object_r:qti_debugfs:s0 tclass=dir permissive=0 ppid=2681 pcomm="main" pgid=19530 pgcomm="hsulaiman.lingu"
2019-10-22 17:46:55.487 19530-19555/com.jwanhsulaiman.lingu I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2019-10-22 17:46:55.491 19530-19555/com.jwanhsulaiman.lingu I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-10-22 17:46:55.492 19530-19555/com.jwanhsulaiman.lingu I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-10-22 17:46:55.492 19530-19555/com.jwanhsulaiman.lingu I/OpenGLRenderer: Initialized EGL, version 1.4
2019-10-22 17:46:55.492 19530-19555/com.jwanhsulaiman.lingu D/OpenGLRenderer: Swap behavior 2
2019-10-22 17:46:55.520 19530-19555/com.jwanhsulaiman.lingu D/vndksupport: Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
2019-10-22 17:46:55.521 19530-19555/com.jwanhsulaiman.lingu D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8998.so from current namespace instead of sphal namespace.
2019-10-22 17:46:56.438 19530-19530/com.jwanhsulaiman.lingu I/AssistStructure: Flattened final assist data: 2648 bytes, containing 1 windows, 10 views
2019-10-22 17:46:56.445 19530-19530/com.jwanhsulaiman.lingu E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2019-10-22 17:46:56.449 19530-19530/com.jwanhsulaiman.lingu I/chatty: uid=10082(com.jwanhsulaiman.lingu) identical 2 lines
2019-10-22 17:46:56.449 19530-19530/com.jwanhsulaiman.lingu E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2019-10-22 17:47:00.065 19530-19628/com.jwanhsulaiman.lingu D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-10-22 17:47:00.569 19530-19628/com.jwanhsulaiman.lingu E/Volley: [28257] BasicNetwork.performRequest: Unexpected response code 404 for https://parts-of-speech.info/tagger/tagger/
2019-10-22 17:47:00.581 19530-19530/com.jwanhsulaiman.lingu W/System.err: com.android.volley.ClientError
2019-10-22 17:47:00.581 19530-19530/com.jwanhsulaiman.lingu W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:199)
2019-10-22 17:47:00.581 19530-19530/com.jwanhsulaiman.lingu W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
2019-10-22 17:47:00.581 19530-19530/com.jwanhsulaiman.lingu W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
2019-10-22 17:47:00.581 19530-19530/com.jwanhsulaiman.lingu W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
这是 Jsoup 的代码:
Connection.Response response =
Jsoup.connect(stringurl)
.userAgent("Mozilla/5.0")
.timeout(10 * 1000)
.method(Method.POST)
.data("text", text)
.data("language", "en")
.followRedirects(true)
.execute();
Document document = response.parse();
它在“执行”时崩溃:
2019-10-22 18:39:56.390 29720-29720/? I/hsulaiman.ling: Late-enabling -Xcheck:jni
2019-10-22 18:39:56.546 29720-29720/? W/hsulaiman.ling: JIT profile information will not be recorded: profile file does not exits.
2019-10-22 18:39:56.547 29720-29720/? I/chatty: uid=10082(com.jwanhsulaiman.lingu) identical 10 lines
2019-10-22 18:39:56.548 29720-29720/? W/hsulaiman.ling: JIT profile information will not be recorded: profile file does not exits.
2019-10-22 18:39:56.561 29720-29720/? I/Perf: Connecting to perf service.
2019-10-22 18:39:56.572 29720-29720/? I/InstantRun: starting instant run server: is main process
2019-10-22 18:39:56.700 29720-29720/? W/hsulaiman.ling: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-10-22 18:39:56.701 29720-29720/? W/hsulaiman.ling: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-10-22 18:39:56.782 29720-29720/? D/OpenGLRenderer: Skia GL Pipeline
2019-10-22 18:39:56.835 29720-29740/? I/Adreno: QUALCOMM build : 7ae04e7, Ia74c9b5270
Build Date : 09/20/18
OpenGL ES Shader Compiler Version: EV031.25.03.00
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.7.4.R1.09.00.00.453.030
Remote Branch : NONE
Reconstruct Branch : NOTHING
2019-10-22 18:39:56.836 29720-29740/? I/Adreno: Build Config : S L 6.0.7 AArch64
2019-10-22 18:39:56.836 29720-29740/? D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8998.so from current namespace instead of sphal namespace.
2019-10-22 18:39:56.831 29720-29720/? W/RenderThread: type=1400 audit(0.0:379229): avc: denied { search } for name="proc" dev="debugfs" ino=11046 scontext=u:r:untrusted_app:s0:c82,c256,c512,c768 tcontext=u:object_r:qti_debugfs:s0 tclass=dir permissive=0 ppid=2681 pcomm="main" pgid=29720 pgcomm="hsulaiman.lingu"
2019-10-22 18:39:56.841 29720-29740/? I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2019-10-22 18:39:56.844 29720-29740/? I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-10-22 18:39:56.844 29720-29740/? I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-10-22 18:39:56.844 29720-29740/? I/OpenGLRenderer: Initialized EGL, version 1.4
2019-10-22 18:39:56.844 29720-29740/? D/OpenGLRenderer: Swap behavior 2
2019-10-22 18:39:56.895 29720-29740/? D/vndksupport: Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
2019-10-22 18:39:56.896 29720-29740/? D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8998.so from current namespace instead of sphal namespace.
2019-10-22 18:39:58.981 29720-29720/com.jwanhsulaiman.lingu I/AssistStructure: Flattened final assist data: 2648 bytes, containing 1 windows, 10 views
2019-10-22 18:39:58.990 29720-29720/com.jwanhsulaiman.lingu E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2019-10-22 18:39:58.992 29720-29720/com.jwanhsulaiman.lingu I/chatty: uid=10082(com.jwanhsulaiman.lingu) identical 2 lines
2019-10-22 18:39:58.992 29720-29720/com.jwanhsulaiman.lingu E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2019-10-22 18:40:02.846 29720-29720/com.jwanhsulaiman.lingu D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-10-22 18:40:02.851 29720-29720/com.jwanhsulaiman.lingu D/AndroidRuntime: Shutting down VM
2019-10-22 18:40:02.853 29720-29720/com.jwanhsulaiman.lingu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jwanhsulaiman.lingu, PID: 29720
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6612)
at android.view.View.performClickInternal(View.java:6581)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25904)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6706)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6612)
at android.view.View.performClickInternal(View.java:6581)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25904)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6706)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:117)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
at java.net.InetAddress.getAllByName(InetAddress.java:1154)
at com.android.okhttp.Dns$1.lookup(Dns.java:39)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:175)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:141)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:83)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:174)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:26)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:730)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:705)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:295)
at com.jwanhsulaiman.lingu.MainActivity.buttonOnClick(MainActivity.java:68)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6612)
at android.view.View.performClickInternal(View.java:6581)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25904)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6706)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-10-22 18:40:02.869 29720-29720/com.jwanhsulaiman.lingu I/Process: Sending signal. PID: 29720 SIG: 9
我应该接收一个 JSON 对象,例如:
{
"taggedText": "John_NNP likes_VBZ the_DT blue_JJ house_NN at_IN the_DT end_NN of_IN the_DT street_NN ._. "
}
我在网上搜索了解决方案,但没有成功。达到预期结果的最佳方法是什么?
最佳答案
尝试如下。
JSONObject parameters = new JSONObject();
try {
parameters.put("text" , "sample text");
parameters.put("language", "en");
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.POST, stringurl, parameters,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//TODO: handle success
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
//TODO: handle failure
}
});
Volley.newRequestQueue(this).add(jsonRequest);
更新
来自您的跟踪记录
Unexpected response code 404 for https://parts-of-speech.info/tagger/tagger/
我使用 postman
测试您的 URL,它会像您一样给出 response 404
。但是当我尝试不使用最后一个反斜杠时,它工作得很好。
您应该从网址中删除最后一个反斜杠。你的网址应该是这样的
stringurl = "https://parts-of-speech.info/tagger/tagger"
关于java - 发送带参数的 POST 请求并读取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58506272/
我正在尝试从该网站抓取历史天气数据: http://www.hko.gov.hk/cis/dailyExtract_uc.htm?y=2016&m=1 在阅读了 AJAX 调用后,我发现请求数据的正确
我有两个 postman 请求 x,y,它们命中了两个不同的休息 api X,Y 中的端点。 x 会给我一个身份验证 token ,这是发出 y 请求所必需的。如何在请求 y 中发出请求 x ?也就是
我使用请求库通过 API 与其他服务器进行通信。但现在我需要同时发送多个(10 个或更多)POST 请求,并且只有在所有响应都正确的情况下才能进一步前进。通常语法看起来有点像这样: var optio
背景:当用户单击按钮时,其类会在class1和class2之间切换,并且此数据是通过 AJAX 提交。为了确认此数据已保存,服务器使用 js 进行响应(更新按钮 HTML)。 问题:如果用户点击按钮的
我正在将 Node.js 中的请求库用于 Google 的文本转语音 API。我想打印出正在发送的请求,如 python example . 这是我的代码: const request = requi
我经常使用requests。最近我发现还有一个 requests2 和即将到来的 requests3 虽然有一个 page其中简要提到了 requests3 中的内容,我一直无法确定 requests
我正在尝试将图像发送到我的 API,然后从中获取结果。例如,我使用发送一个 bmp 图像文件 file = {"img": open("img.bmp)} r = requests.post(url,
我发现 Google Cloud 确保移出其物理环境的任何请求都经过强制加密,请参阅(虚拟机到虚拟机标题下的第 6 页)this link Azure(和 AWS)是否遵循类似的程序?如果有人能给我指
我有一个 ASP.NET MVC 应用程序,我正在尝试在 javascript 函数中使用 jQuery 来创建一系列操作。该函数由三部分组成。 我想做的是:如果满足某些条件,那么我想执行同步 jQu
我找不到如何执行 get http 请求,所以我希望你们能帮助我。 这个想法是从外部url(例如 https://api.twitter.com/1.1/search/tweets.json?q=tw
我的应用只需要使用“READ_SMS”权限。我的问题是,在 Android 6.0 上,当我需要使用新的权限系统时,它会要求用户“发送和查看短信”。 这是我的代码: ActivityCompat.re
我的前端代码: { this.searchInput = input; }}/> 搜索 // search method: const baseUrl = 'http://localho
我有一个由 AJAX 和 C# 应用程序使用的 WCF 服务, 我需要通过 HTTP 请求 header 发送一个参数。 在我的 AJAX 上,我添加了以下内容并且它有效: $.ajax({
我正在尝试了解如何使用 promises 编写代码。请检查我的代码。这样对吗? Node.js + 请求: request(url, function (error, response, body)
如果失败(除 HTTP 200 之外的任何响应代码),我需要重试发送 GWT RPC 请求。原因很复杂,所以我不会详细说明。到目前为止,我在同一个地方处理所有请求响应,如下所示: // We
当用户单击提交按钮时,我希望提交表单。然而,就在这种情况发生之前,我希望弹出一个窗口并让他们填写一些数据。一旦他们执行此操作并关闭该子窗口,我希望发出 POST 请求。 这可能吗?如果可能的话如何?我
像 Facebook 这样的网站使用“延迟”加载 js。当你必须考虑到我有一台服务器,流量很大时。 我很感兴趣 - 哪一个更好? 当我一次执行更多 HTTP 请求时 - 页面加载速度较慢(由于限制(一
Servlet 容器是否创建 ServletRequest 和 Response 对象或 Http 对象?如果是ServletRequest,谁在调用服务方法之前将其转换为HttpServletReq
这是维基百科文章的摘录: In contrast to the GET request method where only a URL and headers are sent to the serv
我有一个循环,每次循环时都会发出 HTTP post 请求。 for(let i = 1; i console.log("succes at " + i), error => con
我是一名优秀的程序员,十分优秀!