如何用Josn數据格式实现API接口登陆

yemaoxiang 2018-04-12 11:40:18
我们自己开发一個客户端,利用對方的api接口登陆。我把api的说明发出來,我自己尝試写了一下,写不出來,求指导。
...全文
311 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你可以json序列化你的请求实体,然后搜索下如何模拟post, 或者你可以搜索下RestSharp,用法直接官网简单抄下就行
  • 打赏
  • 举报
回复
就是叫你模拟http请求,WebRequest或者Httpclient都可以
yemaoxiang 2018-04-12
  • 打赏
  • 举报
回复
图好像不清楚,我重传
yemaoxiang 2018-04-12
  • 打赏
  • 举报
回复
引用 8楼PiaoLuoXiaoBai 的回复:
消息返回了,就写个类序列化来接收。。。
你说的我世知道啊,就是写不出来啊。
PiaoLuoXiaoBai 2018-04-12
  • 打赏
  • 举报
回复
消息返回了,就写个类序列化来接收。。。
yemaoxiang 2018-04-12
  • 打赏
  • 举报
回复
引用 6楼PiaoLuoXiaoBai 的回复:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "POST"; request.ContentType = contentType; //request.ReadWriteTimeout = 1000 * 15; //15s //request.Timeout = 1000 * 15; //15s var postBytes = Encoding.UTF8.GetBytes(postDataStr); request.ContentLength = postBytes.Length; //request.CookieContainer = cookie; Stream myRequestStream = request.GetRequestStream(); myRequestStream.Write(postBytes, 0, postBytes.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //response.Cookies = cookie.GetCookies(response.ResponseUri); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString;
这个已经解决了登陆问题,但响应的数据我要咋弄,api接口说明上的看不
PiaoLuoXiaoBai 2018-04-12
  • 打赏
  • 举报
回复
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "POST"; request.ContentType = contentType; //request.ReadWriteTimeout = 1000 * 15; //15s //request.Timeout = 1000 * 15; //15s var postBytes = Encoding.UTF8.GetBytes(postDataStr); request.ContentLength = postBytes.Length; //request.CookieContainer = cookie; Stream myRequestStream = request.GetRequestStream(); myRequestStream.Write(postBytes, 0, postBytes.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //response.Cookies = cookie.GetCookies(response.ResponseUri); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString;
李敢敢 2018-04-12
  • 打赏
  • 举报
回复
request.GetResponse();好像是这样玩吧。。。没玩过
yemaoxiang 2018-04-12
  • 打赏
  • 举报
回复
引用 3楼娃都会打酱油了 的回复:
你可以json序列化你的请求实体,然后搜索下如何模拟post, 或者你可以搜索下RestSharp,用法直接官网简单抄下就行
咋写啊,不会啊!兄弟,能再指点一下么
ApiDebug is a plug for testing RESTful web services, like postman.「接口调试英语版:http调试,post调试,post模拟」 ApiDebug是一个完全开源免费的接口调试插件,该插件可独立使用,数据支持本地存储也可同步至云端。支持post、get、xml、josn等测试。 相比于Postman等插件,apiDebug有完善的接口管理系统(api.crap.cn 可内网部署),系统支持接口、文档等管理等。产品开发来着BAT,拥有丰富的接口开发、调试经验,产品不断更新迭代,更适合国内用户使用。 ApiDebug & CrapApi-Plug(crapApi)区别: ApiDebug为独立插件,与CrapApi接口管理系统接口数据没有互通,能不依赖服务器运行,服务器仅作数据备份 CrapApi-Plug为CrapApi接口管理软件的增强插件,不能单独使用,必须为联网状态才能使用,接口数据与管理系统接口一致 ApiDebug is a browser plug-in for testing RESTful web services.A tool like postman and resteasy. It might be used for testing other HTTP communications too. Support interface debugging (POST, GET), support JSON, XML and other parameters. If you want to save data to you own database, use the API administration tool -CrapApi(a tool to admin interface and save ApiDebug data. CrapApi is open sourced, you also can use the online service, is free to all. The website url is http://api.crap.cn) Suggest「意见&吐槽」 Email:ehsantang@163.com QQ群:515305698 keyword 「关键词」 Restfull,API debug,接口调试,开源接口调试,postman,postmen,resulteasy,http request,http test,https request,https test、接口测试、接口调试、http接口测试、http接口调试、https接口测试、https接口调试、接口开发工具、http模拟工具 Source Code「源码地址」 码云地址:http://git.oschina.net/CrapApi/ApiDebug GitHub:https://github.com/EhsanTang/ApiDebug
通用接口实现类LinkJOS 扩展于:public class LinkJOS extends LinkOAuth2(LinkOAuth2 extends JspEasy) 构造函数 LinkJOS(HttpServletRequest request,HttpServletResponse response) 京东JOS接口访问函数 public String link2(String link,String method,Bag sys,Bag apps,String appSecret,String file,String FileField) 作用:访问京东JOS平台的所有接口 参数: String link,京东JOS平台接口访问地址,目前固定为:https://api.jd.com/routerjson String method,向京东JOS平台提交数据时的方法,需要应用级别参数时建议用POST方法,不需要时用GET(参见后边的实例) Bag sys,系统级别参数书包(一般只需在接口参数文件中放入接口方法即可,参见后边的实例) Bag apps,应用级别参数书包(在接口参数文件中放入必须的应用级别参数,若不需要应用级别参数时直接用new Bag(-1)构造一个空书包即可,参见后边的实例) String appSecret,应用证书中的App Secret,前边已经设置,固定用"@{pPage:app_secret}"即可 String file,调用上传文件接口上传文件(如图片)到京东JOS平台时的文件全名(含相对路径,如:images/logo.png),不是调用上传文件接口时为空字符串即可(参见后边的实例) String FileField,调用上传文件接口上传文件(如图片)到京东JOS平台时的字段名,配合前边的参数,不是调用上传文件接口时为空字符串即可(参见后边的实例) 返回为京东JOS平台接口对应的JSON格式的字符串 JSON文本解析方法 public void parseJson(String json) 作用:解析京东JOS平台接口返回的JSON格式的字符串,并根据内容生成N个对应的书包 参数:String json,京东JOS平台接口返回的JSON格式的字符串 根据JSON文本的内容在系统中生成N个书包,根书包名称为j0,下一层的josn文本内容生成的书包名称用上一层的Key放在上一层的书名中,下边用实例说明寻找对应书包的方法: 如店铺信息查询接口jingdong.vender.shop.query返回的json文本为 { "jingdong_vender_shop_query_responce": { "shop_jos_result": { "open_time": "", "shop_id": "", "category_main_name": "", "category_main": "", "vender_id": "", "brief": "", "logo_url": "", "shop_name": "" } } } 找出店铺信息书包名的方法如下 @{j0:jingdong_vender_shop_query_responce} @{@{pPage:bag}:shop_jos_result} 这时候的@{pPage:bag}即为需要的店铺信息书包名 具体用法请阅读下载包中的《京东卖家如何快速开发网店工具软件》

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧