Java 从android发送post请求

Java 从android发送post请求,java,android,multithreading,android-studio,request,Java,Android,Multithreading,Android Studio,Request,我已经挣扎了好几个小时了。我一直在尝试从我的android应用程序发出post请求。我发现我不能只从主线程发出请求,所以我发现我可以把它放在一个可运行的线程中。我四处寻找答案,尝试了很多人们使用的方法,这些方法对别人有用,但对我来说都不管用。我有点理解的是这个(不适合我): })有简单的方法吗?还了解了okhttp库,我将尝试实现它,但我对gradle和导入外国库并不擅长 这就是我得到的: 11-28 20:49:49.587 10450-10450/? D/dalvikvm: Late-en

我已经挣扎了好几个小时了。我一直在尝试从我的android应用程序发出post请求。我发现我不能只从主线程发出请求,所以我发现我可以把它放在一个可运行的线程中。我四处寻找答案,尝试了很多人们使用的方法,这些方法对别人有用,但对我来说都不管用。我有点理解的是这个(不适合我):

})有简单的方法吗?还了解了okhttp库,我将尝试实现它,但我对gradle和导入外国库并不擅长

这就是我得到的:

 11-28 20:49:49.587 10450-10450/? D/dalvikvm: Late-enabling CheckJNI
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve interface method 14051: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
 11-28 20:49:50.018 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
 11-28 20:49:50.018 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve interface method 14055: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
 11-28 20:49:50.018 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
 11-28 20:49:50.238 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
 11-28 20:49:50.248 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve virtual method 13952: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
 11-28 20:49:50.248 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
 11-28 20:49:50.268 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
 11-28 20:49:50.268 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve virtual method 402: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
 11-28 20:49:50.268 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
 11-28 20:49:50.278 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
 11-28 20:49:50.278 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve virtual method 424: Landroid/content/res/TypedArray;.getType (I)I
 11-28 20:49:50.278 10450-10450/com.example.matic.eventer D/dalvikvm: VFY:replacing opcode 0x6e at 0x0002
 11-28 20:49:50.438 10450-10450/com.example.matic.eventer D/libEGL: loaded /system/lib/egl/libEGL_mali.so
 11-28 20:49:50.458 10450-10450/com.example.matic.eventer D/libEGL:  loaded /system/lib/egl/libGLESv1_CM_mali.so
 11-28 20:49:50.458 10450-10450/com.example.matic.eventer D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
 11-28 20:49:50.498 10450-10454/com.example.matic.eventer D/dalvikvm: GC_CONCURRENT freed 198K, 9% free 9534K/10375K, paused 3ms+32ms, total 128ms
 11-28 20:49:50.518 10450-10450/com.example.matic.eventer D/OpenGLRenderer: Enabling debug mode 0
 11-28 20:49:54.722 10450-10450/com.example.matic.eventer E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
 11-28 20:49:54.722 10450-10450/com.example.matic.eventer E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
 11-28 20:49:56.514 10450-10583/com.example.matic.eventer D/Http Post Response:: org.apache.http.message.BasicHttpResponse@417e0af0
请帮忙。:)
非常感谢您的帮助。

不确定您的错误。
但对于你的问题:

有简单的方法吗?还发现了okhttp库


这篇漂亮的文章比较了所有可用的网络库的各个方面。永远不要考虑自己构建标题、正文和解析响应。此外,重试、取消正在进行的请求、缓存等都可以通过库轻松完成。并在每一个因素上进行改装。我们正在使用它,它是好的。它支持JSON、XML、Jackson、Moshi、Protobuf以及Wire数据格式。您所需要做的就是创建请求主体模型类和响应模型。看看。

好的。首先,感谢大家的回答。:)这很有帮助。我刚刚将okhttp库导入到项目中,从现在起我将使用它。看起来很容易。再次感谢

愿代码与大家同在

真诚地, Matic

检查此项了解排球库,它将使您的生活更轻松。:)
  <uses-permission android:name="android.permission.INTERNET"/>
    exclude 'META-INF/DEPENDENCIES'

    exclude 'META-INF/NOTICE'

    exclude 'META-INF/LICENSE'

    exclude 'META-INF/LICENSE.txt'

    exclude 'META-INF/NOTICE.txt'
 11-28 20:49:49.587 10450-10450/? D/dalvikvm: Late-enabling CheckJNI
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve interface method 14051: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
 11-28 20:49:50.008 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
 11-28 20:49:50.018 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
 11-28 20:49:50.018 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve interface method 14055: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
 11-28 20:49:50.018 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
 11-28 20:49:50.238 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
 11-28 20:49:50.248 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve virtual method 13952: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
 11-28 20:49:50.248 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
 11-28 20:49:50.268 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
 11-28 20:49:50.268 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve virtual method 402: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
 11-28 20:49:50.268 10450-10450/com.example.matic.eventer D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
 11-28 20:49:50.278 10450-10450/com.example.matic.eventer I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
 11-28 20:49:50.278 10450-10450/com.example.matic.eventer W/dalvikvm: VFY: unable to resolve virtual method 424: Landroid/content/res/TypedArray;.getType (I)I
 11-28 20:49:50.278 10450-10450/com.example.matic.eventer D/dalvikvm: VFY:replacing opcode 0x6e at 0x0002
 11-28 20:49:50.438 10450-10450/com.example.matic.eventer D/libEGL: loaded /system/lib/egl/libEGL_mali.so
 11-28 20:49:50.458 10450-10450/com.example.matic.eventer D/libEGL:  loaded /system/lib/egl/libGLESv1_CM_mali.so
 11-28 20:49:50.458 10450-10450/com.example.matic.eventer D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
 11-28 20:49:50.498 10450-10454/com.example.matic.eventer D/dalvikvm: GC_CONCURRENT freed 198K, 9% free 9534K/10375K, paused 3ms+32ms, total 128ms
 11-28 20:49:50.518 10450-10450/com.example.matic.eventer D/OpenGLRenderer: Enabling debug mode 0
 11-28 20:49:54.722 10450-10450/com.example.matic.eventer E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
 11-28 20:49:54.722 10450-10450/com.example.matic.eventer E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
 11-28 20:49:56.514 10450-10583/com.example.matic.eventer D/Http Post Response:: org.apache.http.message.BasicHttpResponse@417e0af0