本篇文章给大家谈谈http接口开发,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
今天给各位分享http接口开发的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
powerbuilder开发http接口,该怎么处理
使用inet,网上有例子,可以下一个看看
简单如下:
inet ln_inet
n_inet_html ln_html
String ls_url
if GetContextService("Internet", ln_inet) = 1 THEN
ln_html = CREATE n_inet_html
ls_url = "sms/http/sendmessage"
ls_url += ...
ln_inet.GetURL(ls_url,ln_html)
DESTROY ln_html
END IF
java如何创建一个简单的http接口?
1.修改web.xml文件
<!-- 模拟HTTP的调用,写的一个http接口 -- <servlet <servlet-nameTestHTTPServer</servlet-name <servlet-classcom.atoz.http.SmsHTTPServer</servlet-class </servlet <servlet-mapping <servlet-nameTestHTTPServer</servlet-name <url-pattern/httpServer</url-pattern </servlet-mapping
2.新建SmsHTTPServer.java文件
package com.atoz.http;
import java.io.IOException; import java.io.PrintWriter;
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
import com.atoz.action.order.SendSMSAction; import com.atoz.util.SpringContextUtil;
public class SmsHTTPServer extends HttpServlet { private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); String content = request.getParameter("content"); //String content = new String(request.getParameter("content").getBytes("iso-8859-1"), "utf-8"); String mobiles = request.getParameter("mobiles"); String businesscode = request.getParameter("businesscode"); String businesstype = request.getParameter("businesstype"); if (content == null || "".equals(content) || content.length() <= 0) { System.out.println("http call failed,参数content不能为空,程序退出"); } else if (mobiles == null || "".equals(mobiles) || mobiles.length() <= 0) { System.out.println("http call failed,参数mobiles不能为空,程序退出"); } else { /*SendSMSServiceImpl send = new SendSMSServiceImpl();*/ SendSMSAction sendSms = (SendSMSAction) SpringContextUtil.getBean("sendSMS"); sendSms.sendSms(content, mobiles, businesscode, businesstype); System.out.println("---http call success---"); } out.close(); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
3.调用http接口
String content = "测试"; content = URLEncoder.encode(content, "utf-8"); String url = "http://localhost:8180/atoz_2014/httpServer?content=" + content + "mobiles=15301895007"; URL httpTest; try { httpTest = new URL(url); BufferedReader in; try { in = new BufferedReader(new InputStreamReader( httpTest.openStream())); String inputLine = null; String resultMsg = null; //得到返回信息的xml字符串 while ((inputLine = in.readLine()) != null) if(resultMsg != null){ resultMsg += inputLine; }else { resultMsg = inputLine; } in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
打字不易,望采纳,谢谢
如何用C# .NEt开发基于http的接口,只支持post方式传参,除webservice以外,谁能给个例子,万分感谢!
private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
/// <summary
/// 创建POST方式的<a href="https://www.baidu.com/s?wd=HTTP%E8%AF%B7%E6%B1%82tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9uWRzuH7-uHb4PHmsPy7b0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPjcYPHnvrjR1PjcvPHn1njbz" target="_blank" class="baidu-highlight"HTTP请求</a
/// </summary
/// <param name="url"请求的URL</param
/// <param name="parameters"随同请求POST的参数名称及参数值字典</param
/// <param name="timeout"请求的超时时间</param
/// <returns</returns
public static string PostHttpResponse(string url, Dictionary<string, string parameters,
int? timeout)
{
try
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException("url");
}
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.ServicePoint.Expect100Continue = false;
request.ServicePoint.UseNagleAlgorithm = false; //是否使用 Nagle 不使用 提高效率
//request.AllowWriteStreamBuffering = false; //数据是否缓冲 false 提高效率
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = DefaultUserAgent;
if (timeout.HasValue)
{
request.Timeout = timeout.Value;
}
else
{
request.Timeout = 20000;
}
Encoding requestEncoding = Encoding.GetEncoding("UTF-8");
//如果需要POST数据
if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in parameters.Keys)
{
if (i 0)
{
buffer.AppendFormat("{0}={1}", key, parameters[key]);
}
else
{
buffer.AppendFormat("{0}={1}", key, parameters[key]);
}
i++;
}
byte[] data = requestEncoding.GetBytes(buffer.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
//获取响应,并设置响应编码
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
{
encoding = "UTF-8"; //默认编码
}
//读取响应流
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
string returnData = reader.ReadToEnd();
reader.Dispose();
response.Close();
return returnData;
}
catch (Exception ex)
{
MessageUtil.ShowWarning(ex.Message);
}
return "";
}
关于http接口开发和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
http接口开发的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、http接口开发的信息别忘了在本站进行查找喔。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~