查看: 1000| 回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

[学Java/C#] 【OA】(急)Java HTTP Post Get 的OA请教怎么做

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
Description
Publish a service on the web with two endpoints:
1. /messages takes a message (a string) as a POST and returns the SHA256 hash digest of
that message (in hexadecimal format)
2. /messages/<hash> is a GET request that returns the original message. A request to a
non-existent<hash> should return a 404 error.

Example
Let’s say you publish to http://mywebsite.com/ (you don’t need a custom domain for this
project, any IP address we can access will do):

$ curl -X POST -H "Content-Type: application/json" -d '{"message": "foo"}' http://mywebsite.com/messages
{
"digest": "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
}

You can calculate that your result is correct on the command line:
$ echo -n "foo" | shasum -a 256
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae -

You can now query your service for the original message:
$ curl
http://mywebsite.com/messages/2c ... fa0f98a5e886266e7ae
{
"message": "foo"
}
$ curl -i
http://mywebsite.com/messages/aa ... aaaaaaaaaaaaaaaaaaa
HTTP/1.0 404 NOT FOUND Content-Type: application/json Content-Length: 36
Server: Werkzeug/0.11.5 Python/3.5.1 Date: Wed, 31 Aug 2016 14:21:11 GMT
{
"err_msg": "Message not found"
}
(your specifics may vary, all that matters is that you get a 404)





作出python了
但是java做不出来(只作出一部分)
请教高手能不能帮一把



上一篇:关于一道API 设计的题目
下一篇:请教一道pdd的OA
🔗
 楼主| twocold 2019-11-8 11:15:29 | 只看该作者
全局:
  1. private static String sha256(String base) {
  2.             try{
  3.                 MessageDigest digest = MessageDigest.getInstance("SHA-256");
  4.                 byte[] hash = digest.digest(base.getBytes("UTF-8"));
  5.                 StringBuffer hexString = new StringBuffer();

  6.                 for (int i = 0; i < hash.length; i++) {
  7.                     String hex = Integer.toHexString(0xff & hash[i]);
  8.                     if(hex.length() == 1) hexString.append('0');
  9.                     hexString.append(hex);
  10.                 }

  11.                 return hexString.toString();
  12.             } catch(Exception ex){
  13.                throw new RuntimeException(ex);
  14.             }
  15.         }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表