Volley的GET和POST方法
首先记得加上权限
<uses-permission android:name="android.permission.INTERNET"/>
XML代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dell.fuwuqicunchu.fuwuqicunchu"
android:orientation="vertical"> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/et_1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="volleyget"
android:onClick="volleyget"
android:layout_weight="1"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="volleypost"
android:onClick="volleypost"
android:layout_weight="1"/>
</LinearLayout> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_2"/>
</LinearLayout>
JAVA代码
package com.example.dell.myfuwuqi; import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast; import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley; import java.util.HashMap;
import java.util.Map; public class webActivity extends AppCompatActivity { EditText et_1;
EditText et_2; RequestQueue requestQueue; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web); et_1=(EditText)findViewById(R.id.et_1);
et_1.setText("http://192.168.1.101:8080/Testweb/testweb.jsp");
et_2=(EditText)findViewById(R.id.et_2); requestQueue =Volley.newRequestQueue(this); } public void volleyget(View view)
{
final ProgressDialog progressDialog = new ProgressDialog(this); StringRequest str = new StringRequest(et_1.getText().toString(), new Response.Listener<String>() {
@Override
public void onResponse(String s) { et_2.setText(s); progressDialog.dismiss(); }
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(webActivity.this, "失败", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
}); requestQueue.add(str); } public void volleypost(View v)
{
final ProgressDialog dialog = new ProgressDialog(this); StringRequest str = new StringRequest(Request.Method.POST, et_1.getText().toString(), new Response.Listener<String>() {
@Override
public void onResponse(String s) { et_2.setText(s); dialog.dismiss(); }
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) { Toast.makeText(webActivity.this, "失败", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map = new HashMap<String,String>(); map.put("name","volley");
return map;
}
}; requestQueue.add(str);
}
}
Volley的GET和POST方法的更多相关文章
- andorid 远程存储中JDK和Volley的GET和POST方法
在操作Volley的时候先添加volley.jar(包) <uses-permission android:name="android.permission.INTERNET" ...
- Volley
Volley 是 Google 推出的轻量级 Android 异步网络请求框架和图片加载框架.在 Google I/O 2013 大会上发布.其适用场景是数据量小,通信频繁的网络操作. 主要特点: ( ...
- Volley全方位解析,带你从源码的角度彻底理解
Volley 是 Google 推出的轻量级 Android 异步网络请求框架和图片加载框架.在 Google I/O 2013 大会上发布.其适用场景是数据量小,通信频繁的网络操作. 主要特点: ( ...
- Android中关于Volley的使用(五)从RequestQueue开始来深入认识Volley
在前面的几篇文章中,我们学习了如何用Volley去网络加载JSON数据,如何利用ImageRequest和NetworkImageView去网络加载数据,而关于Volley的使用,我们都是从下面一行代 ...
- [Android]Volley的使用
Volley是Google I/O 2013上提出来的为Android提供简单快速网络访问的项目.Volley特别适合数据量不大但是通信频繁的场景. 优势 相比其他网络载入类库,Volley 的优势官 ...
- Android Volley入门到精通:定制自己的Request
经过前面两篇文章的学习,我们已经掌握了Volley各种Request的使用方法,包括StringRequest.JsonRequest.ImageRequest等.其中StringRequest用于请 ...
- Android Volley完全解析
1. Volley简介 我们平时在开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进行H ...
- Google Volley框架源码走读
PS一句:最终还是选择CSDN来整理发表这几年的知识点,该文章平行迁移到CSDN.因为CSDN也支持MarkDown语法了,牛逼啊! [工匠若水 http://blog.csdn.net/yanb ...
- Volley源码分析(1)----Volley 队列
Android网络框架很多,但是基于Google自己的volley,无疑是优秀的一款. 网络框架,无外乎解决一下几个问题,队列,缓存,图片异步加载,统一的网络请求和处理等. 一.Volley 队列 启 ...
随机推荐
- Android 大图片预览ViewPager
项目gitHub地址: https://github.com/bm-x/PhotoView 个人项目gitHub地址: https://github.com/anan03/ananwork/tre ...
- 参考:鼠标点击事件(Selenium)
1.鼠标右键点击操作:Actions action = new Actions(driver) ;action.contextClick(driver.findElement(By.xpath(xpa ...
- ECNAScript6简介
ECMAScript6.0(以下简称ES6)是JavaScript语言的下一代标砖,已经在2015年6月正式发布了,它的目标,是使得JavaScript语言可以用来编写负责的大型应用程序 ,成为企业级 ...
- dsp 28377在线升级 实例总结
使用dsp品台28377d来实现在线升级的功能. 方案 : 升级程序 + 应用程序 升级程序 : 主要的目的是将上位机发送过来的应用程序数据(ccs编译生成的.bin文件)烧写到指定位置,之后在跳 ...
- How to fix the conflict between ROS Python and Conda
Problem: Ever since I have installed Conda, ROS does not seem to work. And predictably it is because ...
- C# 类型转换
int 转换 string 转换有两种: 一种是隐式, ; string b = a.ToString(); 一种是显示. sting b=Convert.ToString();
- iOS 开发之崩溃日志分析
1. (js 与webview 交互崩溃)-[CFRunLoopTimer release]: message sent to deallocated instance 0x62398f80 I've ...
- 统计学习中感知机的C++代码
感知机是古老的统计学习方法,主要应用于二类线性可分数据,策略是在给定的超平面上对误差点进行纠正,从而保证所有的点都是正确可分的. 用到的方法是随机梯度下降法,由于是线性可分的,可保证最终在有限步内收敛 ...
- Ubuntu16.04安装Samba
在新装的ubuntu16.04下安装samba. 安装好samba后备份下配置文件: zhuben@zb:~$ sudo apt-get install samba zhuben@zb:~$ cd / ...
- java maven strom 启动异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/storm/topology/IRich ...