大家好.我是新来的,有一个项目,很难开始.请看看里面有没有帮助!谢谢 :) [英] Hi all. I'm new, have a project and having a hard time where to start. Please take a look inside to help! Thanks :)

查看:123
本文介绍了大家好.我是新来的,有一个项目,很难开始.请看看里面有没有帮助!谢谢 :)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


几天前,我决定使用WebAPI编写一个小程序. (确切地说,是Steam WebAPI)

现在,我知道您发送了某种URL(请求),并且它以JSON格式返回了答案. (或者在这种情况下为xml或vdf)

我知道如何编辑此信息(我相信我可以学习:p),但是我不知道如何用C语言请求它们. (发送网址并等待答案)

我有一个建议使用Python来解决所有这些问题,但是我已经有点熟悉C/C ++,所以我想使用它.我找到了这个; http://uriparser.sourceforge.net/ [ ^ ].我在正确的道路上吗?我可以使用这些库从类似的链接中获取* text *吗? * http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=6D52161D23855A4E3319B63ED165272 [ ^ ]

还是用C还有其他方法可以做到这一点?

另外,假设我确实设法使用WebApp来获取一些信息.之后,我将如何发送数据? (例如,添加朋友或邀请玩家加入群组)


请指出正确的方向.

Hi everyone!


Few days ago I decided to use a WebAPI to make a little program. (Steam WebAPI to be exact)

Now, I know you send some sort of URL (request) and it returns an answer in JSON format. (Or xml or vdf in this instance)

I know how to edit this information (I believe I can learn :p) But I have no idea how to request them in C language. (to send a URL and wait for answer)

I got a suggestion to use Python to mess with all this but I''m already kinda familiar with C/C++ so I want to use it. I found this; http://uriparser.sourceforge.net/ [^]. Am I on the right path? Can I fetch *text* from links like this using these Libraries? *http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=6D52161D23855A4E3319B63ED165272E[^]

Or is there any way else to do this in C?

Also, let''s say I did somehow manage to use the WebApp to get some info. After that how would I send datas? (Like, add a friend or invite a player to a group)


Please point me in the right direction. Thanks a lot in advance!

推荐答案

HTTP是一个简单的协议.您建立一个tcp连接并发送一个请求,然后等待响应.您一遍又一遍地重复.对于HTTP 1.0,您总是为每个请求建立新的连接,而在HTTP 1.1中,您可以通过同一连接发送和接收多个请求(您甚至可以使用流水线操作,但是某些HTTP客户端和服务器处理得不好). br/>
请求和响应都包含以下内容:
-正在使用HTTP协议(1.0或1.1)
-如果是请求,则为请求参数(如url);如果是响应,则为请求状态(HTTP状态码)
-标头:这些是仅包含ASCII字符(!!!)的字符串键/值对.
-可选的有效负载(可以是零字节,甚至可以是任意二进制数据)

重要注意事项:
-我不建议在标头中使用unicode字符串(因为它是按照标准的ASCII),但是有可能的话,当客户端和服务器端都在我的控制下时,我会将字符串转换为utf8,然后对url编码字符串或base64编码,然后再发送.如果服务器不是您的服务器,则您不知道服务器如何处理非ASCII字符或url编码.
-在大多数服务器中,请求的url和请求的标头部分都有大小限制(每个服务器中可配置且各不相同),因此请勿尝试在标头键值对中发送大数据或将其编码为查询字符串参数网址!只有有效载荷具有无限大小!使用POST方法,您可以在有效负载中发送键值参数.

如果要使用C/C ++路由,请使用libcurl作为HTTP客户端执行对服务器的请求: http://curl.haxx.se/libcurl/c/libcurl-tutorial.html [ ^ ]
您可以在其网站上找到用于JSON的多种语言的库: http://www.json.org/ [ ^ ]

独立地形成您的项目,我强烈建议学习python.不仅因为处理http很容易,而且因为今天它是最好,最简单的脚本语言之一,具有真正良好的库支持并且完全独立于平台.我总是使用这种语言来原型化HTTP服务器和客户端行为.您可以使用它来实现HTTP服务器端行为,例如cgi或wsgi(通过扩展诸如Apache之类的知名服务器).如果仅使用python(RPython)的子集,则可以使用PyPy将其转换为二进制可执行文件.
工具箱中至少应包含一种脚本语言,而python是一个不错的选择.
HTTP is a simple protocol. You make a tcp connection and send a request then wait for the response. You repeat this over and over. In case of HTTP 1.0 you always make new connections for each request while in HTTP 1.1 you can send and receive multiple requests over the same connection (you can even use pipelining but some HTTP clients and severs don''t handle that well).

Both a request and a response contains the following things:
- HTTP protocol in use (1.0 or 1.1)
- Request parameters (like url) in case of a request or response status (HTTP status code) in case of a response
- Headers: these are string key/value pairs that contain only ASCII characters (!!!).
- Optional payload (it can be zero bytes or even arbitrary binary data)

Some important notes:
- I don''t recommend using unicode strings in the header (because its ASCII according to the standard) however its possible, when both the client and server side is under my control I convert the strings to utf8 and then I url-encode the strings or base64 encode before sending. If the server isn''t yours then you don''t know how the server handles non-ascii characters or url encoding.
- The requested url and the header part of the request has a size limit in most servers (configurable and different in each server) so don''t try to send big data in header key-value pairs or encoded as query string parameters in your url! Only the payload has unlimited size! With POST method you can send key-value parameters in the payload.

If you want to go the C/C++ route then use libcurl as your HTTP client to perform your requests to the server: http://curl.haxx.se/libcurl/c/libcurl-tutorial.html[^]
You can find libraries for a lot of languages for JSON on its website: http://www.json.org/[^]

Independently form your project I highly recommend learning python. Not only because dealing with http is easy in it but because today its one of the best and simplest scripting languages with really good library support and its quite platform independent. I always prototype HTTP server and client behavior in this language. You can use it to implement HTTP server side behavior as cgi or wsgi (by extending well known servers like Apache). If you use only a subset of python (RPython) then you can convert it to binary executables using PyPy.
There should be at least one scripting language in your toolbox and python is a really good choice.


这篇关于大家好.我是新来的,有一个项目,很难开始.请看看里面有没有帮助!谢谢 :)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆