关于开发http接口的信息

网友投稿 312 2023-02-28


本篇文章给大家谈谈开发http接口,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 今天给各位分享开发http接口的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java 开发HTTP接口

response.write("<?xml version=\"1.0\" encoding=\"utf-8\"?<root<product<fruit name=\"orange\" /</product</root");这是最基本的实现.

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接口

一个servlet接口就可以了啊:

HTTP Header 请求实例

下面的实例使用 HttpServletRequest 的 getHeaderNames() 方法读取 HTTP 头信息。该方法返回一个枚举,包含与当前的 HTTP 请求相关的头信息。

一旦我们有一个枚举,我们可以以标准方式循环枚举,使用 hasMoreElements() 方法来确定何时停止,使用 nextElement() 方法来获取每个参数的名称。

//导入必需的 java 库
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/DisplayHeader")
//扩展 HttpServlet 类
public class DisplayHeader extends HttpServlet {
// 处理 GET 方法请求的方法
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// 设置响应内容类型
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String title = "HTTP Header 请求实例 - 菜鸟教程实例";
String docType =
"<!DOCTYPE html \n";
out.println(docType +
"<html\n" +
"<head<meta charset=\"utf-8\"<title" + title + "</title</head\n"+
"<body bgcolor=\"#f0f0f0\"\n" +
"<h1 align=\"center\"" + title + "</h1\n" +
"<table width=\"100%\" border=\"1\" align=\"center\"\n" +
"<tr bgcolor=\"#949494\"\n" +
"<thHeader 名称</th<thHeader 值</th\n"+
"</tr\n");
Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
String paramName = (String)headerNames.nextElement();
out.print("<tr<td" + paramName + "</td\n");
String paramValue = request.getHeader(paramName);
out.println("<td " + paramValue + "</td</tr\n");
}
out.println("</table\n</body</html");
}
// 处理 POST 方法请求的方法
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}

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方式的HTTP请求  
        /// </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 "";
        }

如何使用jsp 开发 http接口

response.write("<?xml version=\"1.0\" encoding=\"utf-8\"?<root<product<fruit name=\"orange\" /</product</root");这是最基本的实现. 关于开发http接口和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。 开发http接口的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、开发http接口的信息别忘了在本站进行查找喔。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Vue v2.4中新增的$attrs及$listeners属性使用教程
下一篇:HashSet和TreeSet使用方法的区别解析
相关文章

 发表评论

暂时没有评论,来抢沙发吧~