C # Call the gold data API,

Source: Internet
Author: User

C # Call the gold data API,

First of all, spit out the gold data API documentation http://help.jinshuju.net/articles/api-intro.html written very rough ah... anyway, I am not too clear

The form api is used as an example to show you only an address.https://jinshuju.net/api/v1/forms/ex27t2And then, if there is no more, you can guess it.ex27t2It should be changed, but what should I fill in...

 

Here, you should enter a value in your form. It seems that this value is only available in such places. I have not found this value in other places ..

In addition, it is useless to submit a consulting ticket. The reply message only replied, "we currently do not provide such technical support. If you have other questions, open a ticket. If you have any questions, please refer to our help center. Welcome to the official website of golden data (Golden data service No./jinshuju-service )."

Do it by yourself...

Okay, I don't want to talk about anything else. Just go to the code.

Public class JinShuJu {private static string Key = "9hh6fIbLOqDrgin4Q_r6X"; private static string Secret = "z3RSib8HeQBfau6zwRpRo "; /// <summary> /// obtain the form API /// </summary> /// <returns> </returns> public static string GetFromAPI () {string uri = "https://jinshuju.net/api/v1/forms/RsE5EC"; string result = string. empty; WebRequest request = WebRequest. create (new Uri (uri); request. credentials = GetCredentialCache (uri, Key, Secret); request. headers. add ("Authorization", GetAuthorization (Key, Secret); request. timeout = 2000; WebResponse response = request. getResponse (); Stream stream = response. getResponseStream (); StreamReader sr = new StreamReader (stream); result = sr. readToEnd (); sr. close (); stream. close (); return result ;} /// <summary> /// submit the data API /// </summary> /// <param name = "JSONData"> </param> /// <returns> </returns> public static string PostFromAPI (string JSONData) {string uri = "https://jinshuju.net/api/v1/forms/RsE5EC"; string result = string. empty; WebRequest request = WebRequest. create (new Uri (uri); request. credentials = GetCredentialCache (uri, Key, Secret); request. headers. add ("Authorization", GetAuthorization (Key, Secret); request. timeout = 2000; byte [] bytes = Encoding. UTF8.GetBytes (JSONData); request. method = "POST"; request. contentType = "application/json"; string paraUrlCoded = JSONData; byte [] payload; payload = System. text. encoding. UTF8.GetBytes (paraUrlCoded); request. contentLength = payload. length; Stream writer = request. getRequestStream (); writer. write (payload, 0, payload. length); writer. close (); WebResponse response = request. getResponse (); Stream stream = response. getResponseStream (); StreamReader sr = new StreamReader (stream); result = sr. readToEnd (); sr. close (); stream. close (); return result ;}# region # generate Http Basic Access Credential # private static CredentialCache GetCredentialCache (string uri, string username, string password) {string authorization = string. format ("{0 }:{ 1}", username, password); CredentialCache credCache = new CredentialCache (); credCache. add (new Uri (uri), "Basic", new NetworkCredential (username, password); return credCache;} private static string GetAuthorization (string username, string password) {string authorization = string. format ("{0 }:{ 1}", username, password); return "Basic" + Convert. toBase64String (new ASCIIEncoding (). getBytes (authorization);} # endregion}

Finally, we have to talk about the gold data API. It is clear that if the verification condition is not met (required or repeated), the gold data will return 400 and give a prompt.

But! No prompt, but the system will return the 400 Bad Request! It took me half a day to understand that the page request did not exist or other requests were wrong, because the prompt of saying yes was not provided ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.