eoLinker-APIShop菜谱大全C#调用示例代码菜谱大全万种菜谱,包含主料、辅料,制作流程等,可按口味、烹饪方式获取。该产品拥有以下APIs:1.获取菜谱信息2.通过口味获取食谱列表3.获取烹饪方式列表4.获取口味列表5.关键字查询食谱6.通过烹饪方式获取食谱列表7.获取菜谱列表注意,该示例代码仅适用于使用该产品前,您需要通过=171申请API服务1.获取菜谱信息usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Net;usingSystem.Text;usingSystem.Web.Script.Serialization;namespaceapishop_sdk{classProgram{/***转发请求到目的主机*@parammethodstring请求方法*@paramurlstring请求地址*@paramparamsDictionarystring,string请求参数*@paramheadersDictionarystring,string请求头*@returnstring**/staticstringapishop_send_request(stringmethod,stringurl,Dictionarystring,stringparam,Dictionarystring,stringheaders){stringresult=string.Empty;try{stringparamData=;if(param!=null&¶m.Count0){StringBuildersbuilder=newStringBuilder();foreach(variteminparam){if(sbuilder.Length0){sbuilder.Append(&);}sbuilder.Append(item.Key+=+item.Value);}paramData=sbuilder.ToString();}method=method.ToUpper();if(method==GET){url=string.Format({0}?{1},url,paramData);}HttpWebRequestwbRequest=(HttpWebRequest)WebRequest.Create(url);if(method==GET){wbRequest.Method=GET;}elseif(method==POST){wbRequest.Method=POST;wbRequest.ContentType=application/x-=Encoding.UTF8.GetByteCount(paramData);using(StreamrequestStream=wbRequest.GetRequestStream()){using(StreamWriterswrite=newStreamWriter(requestStream)){swrite.Write(paramData);}}}HttpWebResponsewbResponse=(HttpWebResponse)wbRequest.GetResponse();using(StreamresponseStream=wbResponse.GetResponseStream()){using(StreamReadersread=newStreamReader(responseStream)){result=sread.ReadToEnd();}}}catch{return;}returnresult;}classResponse{publicstringstatusCode;}staticvoidMain(string[]args){stringmethod=POST;stringurl==newDictionarystring,string();param.Add(apiKey,your_api_key);//需要从(menuID,);//菜谱IDDictionarystring,stringheaders=null;stringresult=apishop_send_request(method,url,param,headers);if(result==){//返回内容异常,发送请求失败Console.WriteLine(发送请求失败);return;}Responseres=newJavaScriptSerializer().DeserializeResponse(result);if(res.statusCode==000000){//状态码为000000,说明请求成功Console.WriteLine(string.Format(请求成功:{0},result));}else{//状态码非000000,说明请求失败Console.WriteLine(string.Format(请求失败:{0},result));}Console.ReadLine();}}}2.通过口味获取食谱列表usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Net;usingSystem.Text;usingSystem.Web.Script.Serialization;namespaceapishop_sdk{classProgram{/***转发请求到目的主机*@parammethodstring请求方法*@paramurlstring请求地址*@paramparamsDictionarystring,string请求参数*@paramheadersDictionarystring,string请求头*@returnstring**/staticstringapishop_send_request(stringmethod,stringurl,Dictionarystring,stringparam,Dictionarystring,stringheaders){stringresult=string.Empty;try{stringparamData=;if(param!=null&¶m.Count0){StringBuildersbuilder=newStringBuilder();foreach(variteminparam){if(sbuilder.Length0){sbuilder.Append(&);}sbuilder.Append(item.Key+=+item.Value);}paramData=sbuilder.ToString();}method=method.ToUpper();if(method==GET){url=string.Format({0}?{1},url,paramData);}HttpWebRequestwbRequest=(HttpWebRequest)WebRequest.Create(url);if(method==GET){wbRequest.Method=GET;}elseif(method==POST){wbRequest.Method=POST;wbRequest.ContentType=application/x-=Encoding.UTF8.GetByteCount(paramData);using(StreamrequestStream=wbRequest.GetRequestStream()){using(StreamWriterswrite=newStreamWriter(requestStream)){swrite.Write(paramData);}}}HttpWebResponsewbResponse=(HttpWebResponse)wbRequest.GetResponse();using(StreamresponseStream=wbResponse.GetResponseStream()){using(StreamReadersread=newStreamReader(responseStream)){result=sread.ReadToEnd();}}}catch{return;}returnresult;}classResponse{publicstringstatusCode;}staticvoidMain(string[]args){stringmethod=POST;stringurl==newDictionarystring,string();param.Add(apiKey,your_api_key);//需要从(taste,);//口味,从“获取口味列表”API获得,例如“甜味”param.Add(page,);//当前页码param.Add(pageSize,);//当前页面菜谱数量Dictionarystring,stringheaders=null;stringresult=apishop_send_request(method,url,param,headers);if(result==){//返回内容异常,发送请求失败Console.WriteLine(发送请求失败);return;}Responseres=newJavaScriptSerializer().DeserializeResponse(result);if(res.statusCode==000000){//状态码为000000,说明请求成功Console.WriteLine(string.Format(请求成功:{0},result));}else{//状态码非000000,说明请求失败Console.WriteLine(string.Format(请求失败:{0},result));}Console.ReadLine();}}}3.获取烹饪方式列表usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Net;usingSystem.Text;usingSystem.Web.Script.Serialization;namespaceapishop_sdk{classProgram{/***转发请求到目的主机*@parammethodstring请求方法*@paramurlstring请求地址*@paramparamsDictionarystring,string请求参数*@paramheadersDictionarystring,string请求头*@returnstring**/staticstringapishop_send_request(stringmethod,stringurl,Dictionarystri