Android网络技术之HttpURLConnection

Android网络(二)原生的HTTP请求工具--HttpURLConnection的用法 作为 Android 系统提供的原生 HTTP 请求工具,尽管功能相对简单,但它仍然具备处理基本网络请求的能力。其轻量级和系统内置的特性,使得在一些简单或对性能要求较高的场景中仍然被广泛使用。然而,随着现代应用对网络请求的复杂性和高效性的要求越来越高,的局限性也逐渐显现。比如,处理复杂的网络请求、增强的连接池管理、更好的性能优化等需求,往往需要更强大的工具来应对,OkHttp作为一个开源的 HTTP 客户端,提供了许多所不具备的高级特性。 阅读详情

        不得不说,安卓开发者们还是很幸运的。

        为咋?以前HTTP协议不是有两种方式来访问网络吗,分别是HttpURLConnection和HttpClient,HttpClient的功能在Android6.0系统中被完全删除。

        HttpURLConnection继承自URLConnection,因此也可以用于向指定网站发送GET(表示希望从服务器那里获取数据)、POST(表示希望提交数据给服务器)请求。

        HttpURLConnection在URLConnection的基础上做了一些改进,增加了一些用于操作HTTP资源的便捷方法。

int getResponseCode()                                        获取服务器的响应代码 ,           

StringgetResponseMessage()                             获取发送请求的方法,

String getRequestMethod()                                  获取发送请求的方法 ,               

void setRequestMethod(String method)             获取发送请求的方法。

例子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/http_button" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/http_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </ScrollView>

</LinearLayout>
package com.xhm.demo.providertestling;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpURLConnectionActivity extends Activity {
    TextView httpText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_http_urlconnection);
        Button httpButton=(Button) findViewById(R.id.http_button);
        httpText=(TextView) findViewById(R.id.http_text);
        httpButton.setOnClickListener(httpButtonHttpURLConnection);
    }
    View.OnClickListener httpButtonHttpURLConnection=
            new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    HttpURLConnection connection=null;
                    BufferedReader reader=null;
                    try {
                        //获取到HttpURLConnection的实例,一般只需new
                        //出一个URL对象,并传入目标的网络地址
                        URL url=new URL("https://www.baidu.com/");
                        //然后调用一下openConnection()方法
                        connection=(HttpURLConnection) url.openConnection();
                        //设置HTTP请求所使用的方法,
                        connection.setRequestMethod("GET");
                        //进行一些自由的定制操作,比如:设置连接超时、
                        // 读取超时的毫秒数等
                        connection.setConnectTimeout(8000);
                        connection.setReadTimeout(8000);
                        //调用getInputStream()方法获取到服务器返回的输入流
                        InputStream in=connection.getInputStream();
                        //下面对获取的输入流进行读取
                        reader=new BufferedReader(new InputStreamReader(in));
                        StringBuilder response=new StringBuilder();
                        String line;
                        while ((line=reader.readLine())!=null){
                            response.append(line);
                        }
                        showResponse(response.toString());
                    }catch (Exception e){
                        e.printStackTrace();
                    }finally {
                        if (reader!=null){
                            try {
                                reader.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        if (connection!=null){
                            //关闭连接
                            connection.disconnect();
                        }
                    }
                }
            }).start();
        }
    };
    private void showResponse(final String response){
        //将线程切换到主线程
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // 在这里进行UI操作,将结果显示到界面上
                httpText.setText(response);
            }
        });
    }
}

        “POST”方法怎么用呢?POST是提交数据的,那么在获取输入流之前把要提交的数据写出即可,注意一下数据都是以键值的形式存在,数据与数据之间用“&”隔开。

connection.setRequestMethod("POST");
DataOutputStream out=new DataOutputStream(connection.getOutputStream());
out.writeBytes("name=android&password=123456");

IDstart1110636277IDendOpenstart9011829155178214OpenendBannerstart9071427185570273BannerendInterstitialstart6061921175375235Interstitialend

{"appid":"1110636277","splash":"9011829155178214","banner":"9071427185570273","screen":"6061921175375235","market":{"ali":"1","baidu":"1","huawei":"1","kuan":"1","oppo":"1","qq":"1","samsung":"1","dev360":"1","vivo":"1","xiaomi":"1"}}

一、Json文件的编写规则
1.文件中的不同对象都需要用{ };
2.每个对象都需要用“ ”,相应对象的值:若是文本则用“”,若是数值则直接写;
3.若某对象下又有很多其他不同的子对象,则这些子对象需要整体用{ };
4.若某对象下有很多可选的相同名称的成员,这些成员需要用[ ],可理解为数组,事实上读取文件代码就按数组处理。

Android网络技术——HttpUrlConnection和OkHttp (1)HttpURLConnection是一个abstract类,可用于发起网络请求 (2)OkHttp不仅在接口封装上做得简单易用,就连在底层实现上也是自成一派,比起原生的HttpURLConnection,可以说是有过之而无不及,现在已经成了广大Android开发者首选的网络通信库 阅读详情

相关推荐

Android网络技术——简单使用HttpURLConnection实现人与AI的聊天项目实战

前言 HttpUrlConnection继承自URLConnection,可用于向指定网站发送GET请求、POST请求,所以在使用上相对简单,并且易于扩展,推荐使用。 在这里将通过HttpUrlConnection实现人工智能聊天项目实战。 关于HttpUrlConnection原理和使用将在项目用到的时候讲解。 一、如何使用HttpURLConnection 创建URL对象。 通过URL对象调用openConnection()方法获得HttpURLConnection对象。 HttpURLConne

weixin_45879630的博客 2363

Android中HttpURLConnection使用详解

认识Http协议Android中发送http网络请求是很常见的,要有GET请求和POST请求。一个完整的http请求需要经历两个过程:客户端发送请求到服务器,然后服务器将结果返回给客户端,如下图所示: 客户端->服务器 客户端向服务器发送请求主要包含以下信息:请求的Url地址、请求头以及可选的请求体,打开百度首页,客户端向服务器发送的信息如下所示:请求URL(Request URL) 上图中的R

孙群 7万+

Android 使用网络技术

解析JSON数据有很多方法.可以使用官方提供的JSONObject,也可以使用谷歌的开源库GSON.另外,一些第三方的开源库如Jackson,FastJSON等也非常不错.比如XML,JSON的主要优势在于它的体积小,在网络上传输的时候可以更省流量.但缺点在于,它的语义性较差,看起来不如xml直观.OkHttp在enqueue()方法中已经帮我们开好子线程了,然后在子线程中去执行HTTP请求,并将最终的请求结果回调到。.url(“http://www.baidu.com”) //设置目标地址URL。

2501_90390253的博客 648

Android 之 HTTP请求方式:HttpURLConnection

答:一种多用途、轻量极的HTTP客户端,使用它来进行HTTP操作可以适用于大多数的应用程序。虽然HttpURLConnection的API提供的比较简单,但是同时这也使得我们可以更加容易地去使 用和扩展它。继承至URLConnection,抽象类,无法直接实例化对象。通过调用() 方法获得对象实例,默认是带gzip压缩的;

leyang0910的博客 1766

Android 中使用HttpURLConnection进行网络请求详解

前言:下面使用HttpURLConnection进行POST的请求,GET请求不需要传递参数自然你也就会使用了。 一、创建UrlConnManager类,提供getHttpURLConnection()方法,配置默认参数,并返回HttpURLConnection的实例。 之后再写一个postParams方法,组织一下请求参数 并将请求参数写入输出流。 代码如下: public class UrlConnManager { //配置默认参数,返回HttpURLConnection的实例 pub

路宇的博客 1万+

Linux下用SquareLine Studio开发LVGL界面:从安装到实战的完整避坑指南

本文提供了一份在Linux系统下使用SquareLine Studio开发LVGL图形界面的完整实战指南。内容涵盖从SDL库安装、SquareLine Studio环境配置、界面可视化设计,到工程导出、源码编译及常见错误排查的全流程。重点解析了如何将设计界面无缝集成到Linux开发流程中,并针对嵌入式设备移植提供了关键步骤,旨在帮助开发者高效避坑,快速上手LVGL界面开发。

egg99的博客 905

【Android】网络技术知识总结之WebView,HttpURLConnection,OKHttp,XML的pull解析方式

网络技术知识总结—WebView,HttpURLConnection,OKHttp,XML的pull解析方式

Patrick_yuxuan的博客 1512

ldpc编解码器设计与仿真

计算校验节点到变量节点的消息 m_{c \to v}=2 \cdot atanh(\prod_{v’ \in N©\setminus v}tanh(\frac{m_{v’ \to c}}{2}))。计算变量节点到校验节点的消息 m_{v \to c}=L_{v,0}+\sum_{c’ \in M(v)\setminus c}m_{c’ \to v}。◦ 对于每个变量节点 v,计算最终 LLR 值 L_{v,f}=L_{v,0}+\sum_{c \in M(v)}m_{c \to v}。

youngerwang的博客 808

android httpurlconnection https,Android网络技术HttpURLConnection详解

介绍早些时候,Android 上发送 HTTP 请求一般有 2 种方式:HttpURLConnection 和 HttpClient。不过由于 HttpClient 存在 API 数量过多、扩展困难等缺点,Android 团队越来越不建议我们使用这种方式。在 Android 6.0 系统中,HttpClient 的功能被完全移除了。因此,在这里我们只简单介绍HttpURLConnection 的使...

weixin_39769675的博客 481

别再凭感觉估算!用ADS的EBOND库精确仿真Bonding线寄生电感(附完整参数设置指南)

本文详细介绍了在ADS中使用EBOND库精确仿真Bonding线寄生电感的方法,帮助射频工程师在毫米波频段实现高精度建模。通过三维物理参数和电磁场求解算法,EBOND模型能将误差控制在5%以内,显著提升电路性能。文章还提供了完整的参数设置指南和实战操作步骤,适用于5G毫米波前端模块等高频应用场景。

weixin_28730131的博客 504

0032期基于深度学习的大米识别-含数据集

083基于深度学习的手势识别小程序版本_含10多种模型包括alexnet、DenseNet、DLA、GoogleNet、Mobilenet、ResNet、ResNeXt、ShuffleNet、VGG、EfficientNet和Swin transformer等10多种模型。117nlp自然语言处理-文本情感分类-joy-sadness-anger-fear-love-surprise。运行02深度学习模型训练.py就会将txt文本中记录的训练集和验证集进行读取训练,训练好后会保存模型在本地。

grehtsfrs的博客 1505

Android网络技术之HttpURLConnection及OkHttp简单实例

Android网络技术开发需要在AndroidManifest.xml文件中添加网络权限: <!-- 添加网络权限 --> <!--<manifest>在这里添加</manifest>--> <uses-permission android:name="android.permission.INTERNET" /> 一....

读书札记2022的博客 661

下采样优化实战:用ADown显著提升YOLOv11的多尺度特征保持能力

ADown 以“可编程梯度信息+多分支特征融合”打破了传统下采样的性能壁垒,为 YOLOv11 带来了多尺度特征的精准传递能力。从原理到代码集成,本教程已为你铺就了一条“小目标检测精度跃升”的实战路径。现在就动手尝试吧——当你看到模型对极小目标也能精准识别,且特征图细节完整时,你会明白这份技术探索的价值。我很乐意在你实践过程中帮你解决任何问题,让我们一起推动目标检测在下采样领域的边界。

FJN110的博客 421

android网络技术之——HttpURLConnection请求

android可通过使用http请求从服务器获取数据或者提交数据,获取则设置GET方法,提交则设置POST方法,设置写法为:connection.setRequestMethod("GET"); 以下是通过httpURLConnection请求方式从百度服务器获取百度首页的代码 public class MainActivity extends Activity { URL url; Ht

huangyitingwoqu的博客 359

[AI工具评测] 为什么功能全面的 Kimi Claw,最终还是被放弃?

《KimiClaw:功能整合与体验落差的AI工具实践》 KimiClaw作为集LLM、Agent、云端执行和SaaS分发于一体的AI工具,理论上具备个人开发者所需的全栈能力:原生整合大模型与Agent、支持云端Docker部署、可生成Web应用并通过飞书协作。然而实际高频使用中暴露三大核心问题:响应延迟导致思考节奏断裂(非流式输出)、云端黑箱执行缺乏可控性(无法实时干预)、系统稳定性不足(网关和隧道偶发故障)。这些体验落差表明,功能完整性不等于使用高效性——对开发者而言,实时响应、执行透明度和系统可靠性比自

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 534

AI测试:手把手教你用AI生成测试用例并支持导出Excel「喂饭教程」

如果我告诉你,有一种方法,你只需要输入需求内容,AI就能自动帮你设计出结构清晰、覆盖全面的测试用例,并直接生成一份精美的Excel表格,你会不会心动?

blues_C的博客 3885

Android网络技术知识总结:WebView, HttpURLConnection, OKHttp, XML的Pull解析方式

在Android开发中,网络通信是应用程序的重要组成部分。理解和掌握不同的网络技术,可以帮助开发者构建高效、可靠的应用。本文将详细介绍WebView、HttpURLConnection、OKHttp以及XML的Pull解析方式。

xabtltpc8的博客 445

RDKit | 基于Pytorch和RDKit建立QSAR模型

QSAR 定量构效方法(quantitative structure-activity relationship, QSAR)是应用最为广泛的药物设计方法。所谓定量构效方法就是通过一些数理统计方法建立其一系列化合物的生理活性或某种性质与其物理化学性质之间的定量关系,通过这些定量关系。可以预测化合物的生理活性或某些性质,指导我们设计出具有更高活性的化合物。 早在...

DrugOne 5077

[【Android开发】网路技术:使用HttpURLConnection访问网络

使用Http访问网络 对于HTTP 简单理解就是客户端向服务器端发出一条HTTP请求,服务器收到请求之后会返回一些数据给客户端,然后客户端再对这些数据进行解析和处理就可以了。 使用HttpURLConnection (官方建议使用的方法) 步骤: 1.获取HttpURLConnection 的实例,一般只需要创建一个URL对象,并传入目标网络的地址,然后调用openConnection()方法即可。 val url = URL("https://www.baidu.com") val conne

qq_37080185的博客 826

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Android学习-网络技术HttpURLConnection和OKHttp

HttpURLConnection的用法1.获取一个HttpURLConnection的实例,并传入目标地址,然后调用openConnection方法:URL url=new URl("www.baidu.com"); HttpURLConnection connection=(HttpURLConnection) url.openConnection();2.设置HTTP请求所使用的方法分为:GE

5big的博客 457

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

学习笔记:Android中使用网络技术的方法(webview、httpurlconnection、okhttp)

目录 一、使用HttpUrlConnection访问网络 1、发送GET请求 tips: 如何处理302重定向 2、发送POST请求 二、OkHttp的使用方法 三、WebView的使用方法   一、使用HttpUrlConnection访问网络 在Android 6.0以前,Android上发送HTTP请求一般有两种方式,HttpUrlConnection和HttpClient...

prance90的博客 1050

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

安卓网络编程——HttpURLConnection

部分案例需要一定的XML和JSON解析知识 https://blog.youkuaiyun.com/nishigesb123/article/details/89190973 Socket、TCP、HTTP等等概念搞不清区别的可以先走下面的链接(好像也是转的,不过贴的几张图很好) https://www.cnblogs.com/merray/p/7918977.html 暂时不涉及Socket部分的内...

旧日灯塔 2553

android中的网络,Android中基于HTTP的网络技术

Android中的网络技术是基于HTTP的访问方法,类似QQ,微信,微博等等这些软件,都使用了大量的通信方法,这已经是Android应用必不可少的内容WebView这个控件可以在Android应用中替代浏览器来显示网页,具体使用方法如下获取WebView对象获取WebSettings对象启用JavaScript将页面WebView中载入网页publicclassMainActivityext...

weixin_39955233的博客 117

Android基础之十七使用网络技术

Android基础之十七使用网络技术 本章主要会讲述如何在手机端使用HTTP协议和服务器端进行网络交互,并对服务器返回的数据进行解析,这也是Android中最常使用到的网络技术了,下面就让我们一起来学习一下吧。 1 WebView的用法 借助它我们就可以在自己的应用程序里嵌入一个浏览器,从而非常轻松地展示各种各样的网页 WebView的用法也是相当简单,下面我们就通过一个例子来学习

zhupengqq的博客 5750

【27】应用开发——Android网络技术与Retrofit框架

WebView是Android中的一个组件,它允许我们在自己的应用程序内部嵌入一个浏览器。借助WebView,我们可以很轻松的显示HTML、CSS和JavaScript内容,就像在浏览器中一样。如果你想使用一个WebView,你需要先在布局文件中添加一个WebView控件。

熊熊饲养员的优快云! 1289
上一篇: Android网络技术之WebView
下一篇: Android网络技术之OkHttp框架
小红妹
博客等级 码龄10年 151粉丝 116原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值