Giter Site home page Giter Site logo

http-login-and-use-cookie's Introduction

HTTP实战: 使用Java代码进行模拟登录

请完成Crawler中的程序,实现对指定的网站的模拟登录。这个过程分为两个步骤:

注意:你可以使用浏览器或者Postman先对这些接口进行测试。测试用户名/密码是xdml/xdml

我们并没有列出完成这个需求的所有细节,因为我们希望能锻炼你自己搜索、阅读文档的能力——这对一个工程师是必不可少的技能。但是,我们仍然希望在你遇到解决不了的问题时能多思考、多问。祝你好运!

第一步,使用给定的用户名username和密码password进行模拟登录

登录接口:http://47.91.156.35:8000/auth/login

发送一个HTTP POST请求到该接口,其Header包括:

  • Content-Type: application/json
  • User-Agent: 伪装成浏览器的User-Agent,否则可能会触发反爬虫系统

Body是:

{"username": "<给定的用户名>", "password": "<给定的密码>"}

提示:这样的JSON字符串可以通过以下方式生成:

Map<String,String> map = new HashMap<>();
map.put("username", <给定的用户名>);
map.put("password", <给定的密码>);
// 然后使用你喜欢的JSON序列化库把这个map序列化成一个JSON字符串
String json = ...

服务器若返回成功的响应,则会在HTTP响应中包含一个形如Set-Cookie: XXXXXXXXX; Path=/; HttpOnly的Header。

第二步,解析Cookie并使用该Cookie发送请求

在拿到第一步中的Set-Cookie: JSESSIONID=XXXXXXXXX; Path=/; HttpOnly后,请使用Java代码获取其中的JSESSIONID=XXXXXXXXX值。

http://47.91.156.35:8000/auth发送一个HTTP GET请求,其Header包括:

Cookie: JSESSIONID=XXXXXXXXX

返回得到的HTTP响应的Body字符串,它是一个JSON字符串。

祝你好运!

在提交Pull Request之前,你应当在本地确保所有代码已经编译通过,并且通过了测试(mvn clean verify)


注意!我们只允许你修改以下文件,对其他文件的修改会被拒绝:


完成题目有困难?不妨来看看写代码啦的相应课程吧!

回到写代码啦的题目,继续挑战!

http-login-and-use-cookie's People

Contributors

hcsp-bot avatar blindpirate avatar colla2me avatar chelegen avatar ayang818 avatar yueyuezone avatar spclock avatar shiliyu avatar shenwl avatar laowang2020 avatar joeypine avatar pingannetbar avatar scott-yuyan avatar ethanwxl avatar sun1341283 avatar magicp avatar maxiaoda avatar mysteryven avatar bridgeren avatar nicknessii avatar pathjh avatar perfectlipeng avatar phlvance avatar calmbook avatar richard1230 avatar silvia-yqy avatar huangchucai avatar linsinan1995 avatar leo2c avatar kungua avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.