本文将带您了解关于如何使用php中的curl通过mongolabrestapi创建基本数据库操作的web服务?的新内容,同时我们还将为您解释php操作mongodb的相关知识,另外,我们还将为您提供关
本文将带您了解关于如何使用php中的curl通过mongolab rest api创建基本数据库操作的web服务?的新内容,同时我们还将为您解释php 操作mongodb的相关知识,另外,我们还将为您提供关于.net – 如何使用HttpWebRequest来调用接受byte []参数的Web服务操作?、Erlang YAWS:如何测试简单的REST Web服务?、java – Restful Web服务如何比基于SOAP的Web服务更好、perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单的实用信息。
本文目录一览:- 如何使用php中的curl通过mongolab rest api创建基本数据库操作的web服务?(php 操作mongodb)
- .net – 如何使用HttpWebRequest来调用接受byte []参数的Web服务操作?
- Erlang YAWS:如何测试简单的REST Web服务?
- java – Restful Web服务如何比基于SOAP的Web服务更好
- perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单
如何使用php中的curl通过mongolab rest api创建基本数据库操作的web服务?(php 操作mongodb)
我是mongodb和mongolab的新手.
任何人都可以告诉我如何通过PHP中的curl访问mongolab数据库,而不是通过ajax.
我想创建api,如LOGIN,RESET_PASSWORD,RESIGTRATION.
如何创建上述Web服务.
我已经提交了https://support.mongolab.com/entries/20433053-REST-API-for-MongoDB文件.
提前致谢…
解决方法:
如果您正在运行支持PHP的服务器,我建议您使用MongoDB PHP driver进行连接. MongoLab REST API实际上适用于不需要服务器的应用程序.
.net – 如何使用HttpWebRequest来调用接受byte []参数的Web服务操作?
让我们说我的方法是这样的
[WebMethod] public string TestMethod(string a) { return a; }
我在C#中使用HttpRequest这样称呼它
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Credentials = CredentialCache.DefaultCredentials; req.Method = "POST"; // Set the content type of the data being posted. req.ContentType = "application/x-www-form-urlencoded"; string inputData = "sample webservice"; string postData = "a=" + inputData; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] byte1 = encoding.GetBytes(postData); using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) { StreamReader sr = new StreamReader(res.GetResponseStream()); string txtOutput = sr.ReadToEnd(); Console.WriteLine(sr.ReadToEnd()); }
这完全没问题.现在我有另一个像这样定义的web方法
[WebMethod] public string UploadFile(byte[] data)
我试着这样称呼它
ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "data=abc"; byte[] sendBytes = encoding.GetBytes(postData); req.ContentLength = sendBytes.Length; Stream newStream = req.GetRequestStream(); newStream.Write(sendBytes,sendBytes.Length);
但这给了我一个500内部错误:(
解决方法
首先是Header设置,如果您的Web服务可以通过Web执行并发送参数,则可以获得此设置.我使用Chrome中的开发人员工具.简单的方法是查看webservice的描述(即http://myweb.com/WS/MyWS.asmx?op = Validation)
WebRequest request = WebRequest.Create(http://myweb.com/WS/MyWS.asmx?op=Validation); request.Method = "POST"; ((HttpWebRequest)request).UserAgent = ".NET Framework Example Client"; request.ContentType = "text/xml; charset=utf-8"; ((HttpWebRequest)request).Referer = "http://myweb.com/WS/MyWS.asmx?op=Validation"; ((HttpWebRequest)request).Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; ((HttpWebRequest)request).Host= "myweb.com"; request.Headers.Add("SOAPAction","http://myweb.com/WS/Validation");
然后是请求部分
string message = "a=2"; string envelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+ "<soap:Body><Validation xmlns=\"http://myweb.com/WS\"><data>@Data</data></Validation></soap:Body></soap:Envelope>"; string SOAPmessage = envelope.Replace("@Data",System.Web.HttpUtility.HtmlEncode(message)); // The message must be converted to bytes,so it can be sent by the request byte[] data = Encoding.UTF8.GetBytes(SOAPmessage); request.ContentLength = data.Length; request.Timeout = 20000; Stream dataStream = request.GetRequestStream(); dataStream.Write(data,data.Length); dataStream.Close(); WebResponse response = request.GetResponse(); Stream inputStream = response.GetResponseStream();
现在,您可以从响应中获取传入的流
请记住根据Web服务的页面详细信息(即http://myweb.com/WS/MyWS.asmx?op = Validation)给出的描述来调整SOAP信封和要发送的参数.
Erlang YAWS:如何测试简单的REST Web服务?
如果每个“send-request-get-request-test”测试都可以在EUnit中运行(可以使用测试生成器),那就太好了.
我还希望能够使用rebar(make test)运行这组测试.
最近I used ibrowse在另一个应用程序(Mochiweb),但我发现它安静使用繁琐.
是否还有其他选项来编写可以将HTTP请求发送到YAWS RESTful应用程序的Erlang / OTP测试?最常见的方法是什么?
解决方法
java – Restful Web服务如何比基于SOAP的Web服务更好
– Restful Web服务将每个服务方法视为一种资源,并给它一个URI ..
然而,我不明白这些答案的全部意义.至于为什么这些事情证明比基于SOAP的Web服务有如此大的优势.
一个例子将不胜感激
解决方法
带宽是REST的主要优点,因为没有复杂的文档遍历(即XML,SOAP头),这对于良好的Web API来说是非常重要的. JSON是用于数据交换的广泛认可和简单的标准,并且可以通过浏览器和客户端代码轻松阅读,这就是为什么大多数RESTful API(雅虎是一个很好的例子)提供了JSON.
更不用说REST可用于XmlHttpRequest对象,这对于Web API的AJAX能力也是至关重要的.
当然,REST的缓存功能当然不能忽视.由于REST基于HTTP,因此可以利用HTTP(和Web本身)的许多语义,通过使用HTTP数据包(expires)上的标头来启用浏览器的缓存.更不用提gzip压缩来提高效率了.性能方面,REST实际上是通过SOAP来完成的.
对于SOAP来说,SOAP适用于状态操作. WS *标准(安全性,事务处理等)处理这种在分布式场景中相当普遍的管道.可以使用REST来完成REST,但是它不会真的是REST. SOAP对于定义客户端和服务器之间的操作合同非常有用,这在分布式场景中至关重要.
所以我的意见(以及整个SOAP与REST的事情都是高度评价的),将SOAP用于分布式计算场景,将REST用于Web API.
perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单
我已在管理控制台中导入此 Restfull Web service并使用此URL成功创建并获取票证信息
http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/1.
但问题是当我获得票证信息时链接的配置项信息不会出现.
我在google上做了很多搜索,发现票证可以通过OTRS GUI链接到Config Item,在AgentTicketzoom页面中会显示,我希望通过Web服务完成.
任何人都可以帮助我解决这个问题,或者建议一些关于如何创建Web服务以从票证中获取链接对象信息的文档.
更新#1
我成功地将web控制器添加到我现有的Ticket连接器.网址是http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject与POST Call.but我收到此错误
{“faultcode”:“Server”,“faultstring”:“没有ConfigObject!”}
我也检查了初始参数
$VAR1 = { 'Password' => '1234567','RequestMethod' => 'POST','SourceKey' => '1','SourceObject' => 'Ticket','State' => 'valid','TargetKey' => '2','Targetobject' => 'ITSMConfigItem','Type' => 'ParentChild','UserID' => '1','UserLogin' => 'XXXXX.XXXX@XXXX.com'}; $VAR1 = { 'ErrorMessage' => 'Got no ConfigObject!','Success' => 0};
解决方法
首先,您应该编写一个新的通用接口连接器操作,该操作将处理来自LinkObject类的方法LinkAdd(APIdoc)
然后通过新的XML文件创建并注册新操作,如下所示:
文件名:GenericInterfaceLinkObjectConnector.xml
<?xml version="1.0" encoding="utf-8"?> <otrs_config version="1.0" init="Application"> <ConfigItem Name="GenericInterface::Operation::Module###LinkObject::LinkAdd" required="0" Valid="1"> <Description Translatable="1">GenericInterface module registration for the operation layer.</Description> <Group>GenericInterface</Group> <SubGroup>GenericInterface::Operation::ModuleRegistration</SubGroup> <Setting> <Hash> <Item Key="Name">LinkAdd</Item> <Item Key="Controller">LinkObject</Item> <Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item> </Hash> </Setting> </ConfigItem> </otrs_config>
之后,您可以从OTRS GUI发布新的提供程序WebService,其中使用了新创建的连接器.
确保您传递了方法所需的所有参数!
$True = $LinkObject->LinkAdd( SourceObject => 'Ticket',SourceKey => '321',Targetobject => 'FAQ',TargetKey => '5',Type => 'ParentChild',State => 'Valid',UserID => 1,);
更新:
请阅读此Document以了解如何构建通用接口,然后请添加新的连接器(LinkObject)
注册连接器及其操作 – 将XML文件放在/ Kernel / Config / Files / …
然后转到Sysconfig – > GenericInterface – > GenericInterface :: Operation :: ModuleRegistration并在GenericInterface :: Operation :: Module ### LinkObject :: LinkAdd旁边设置一个勾号并保存更改
然后将此Connector文件添加到/Custom/Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm
# -- # Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation backend # copyright (C) 2016 ArtyCo (Artjoms Petrovs),http://artjoms.lv/ # -- # This software comes with ABSOLUTELY NO WARRANTY. For details,see # the enclosed file copYING for license information (AGPL). If you # did not receive this file,see http://www.gnu.org/licenses/agpl.txt. # -- package Kernel::GenericInterface::Operation::LinkObject::LinkAdd; use strict; use warnings; use Kernel::GenericInterface::Operation::Common; use Kernel::System::LinkObject; use Kernel::System::VariableCheck qw(IsstringWithData IsHashRefWithData); =head1 NAME Kernel::GenericInterface::Operation::LinkObject::LinkAdd - GenericInterface Link Create Operation backend =head1 SYnopSIS =head1 PUBLIC INTERFACE =over 4 =cut =item new() usually,you want to create an instance of this by using Kernel::GenericInterface::Operation->new(); =cut sub new { my ( $Type,%Param ) = @_; my $Self = {}; bless( $Self,$Type ); # check needed objects for my $Needed ( qw(DebuggerObject ConfigObject MainObject logobject TimeObject DBObject EncodeObject WebserviceID) ) { if ( !$Param{$Needed} ) { return { Success => 0,ErrorMessage => "Got no $Needed!" }; } $Self->{$Needed} = $Param{$Needed}; } # create additional objects $Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} ); $Self->{LinkObject} = Kernel::System->LinkObject->new( %{$Self} ); return $Self; } =item Run() Create a new link. my $Result = $OperationObject->Run( Data => { SourceObject => 'Ticket',Targetobject => 'Ticket',TargetKey => '12345',},); $Result = { Success => 1,# 0 or 1 ErrorMessage => '',# In case of an error Data => { Result => 1,# 0 or 1 },}; =cut sub Run { my ( $Self,%Param ) = @_; # check needed stuff if ( !IsHashRefWithData( $Param{Data} ) ) { return $Self->{CommonObject}->ReturnError( ErrorCode => 'LinkAdd.MissingParameter',ErrorMessage => "LinkAdd: The request is empty!",); } my $LinkID = $Self->{LinkObject}->LinkAdd( %Param,); if ( !$LinkID ) { return $Self->{CommonObject}->ReturnError( ErrorCode => 'LinkAdd.AuthFail',ErrorMessage => "LinkAdd: Authorization failing!",); } return { Success => 1,Data => { Result => $LinkID,}; } 1; =back =head1 TERMS AND CONDITIONS This software is part of the OTRS project (L<http://otrs.org/>). This software comes with ABSOLUTELY NO WARRANTY. For details,see the enclosed file copYING for license information (AGPL). If you did not receive this file,see L<http://www.gnu.org/licenses/agpl.txt>. =cut
然后它应该出现,可以从管理员使用 – > Web服务 – >可用操作下拉列表当然可以用作Web服务.
PHP使用示例如下所示:
#### Initialize new client session #### $client = new SoapClient( null,array( 'location' => $url,'uri' => "Core",'trace' => 1,'login' => $username,'password' => $password,'style' => SOAP_RPC,'use' => SOAP_ENCODED ) ); #### Create and send the SOAP Function Call #### $success = $client->__soapCall("dispatch",array($username,$password,"LinkObject","LinkAdd","SourceObject",'Ticket',"SourceKey",$ticket_id1,"Targetobject","TargetKey",$ticket_id2,"Type",'ParentChild',"State",'Valid',"UserID",'1' ));
如果出现错误 – 启用调试,请查看系统日志并检查OTRS的所有初始设置
祝你好运!
更新#2
要注册Web服务 – 按“添加新的Web服务”按钮,根据需要对其进行命名并设置以下设置(选择LinkAdd操作)并保存
更新#3
这是OTRS 5的更新模块文件
# -- # Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation backend # copyright (C) 2016 ArtyCo (Artjoms Petrovs),$Type ); # check needed objects for my $Needed ( qw( DebuggerObject WebserviceID ) ) { if ( !$Param{$Needed} ) { return { Success => 0,ErrorMessage => "Got no $Needed!" }; } $Self->{$Needed} = $Param{$Needed}; } # create additional objects $Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} ); $Self->{LinkObject} = $Kernel::OM->Get('Kernel::System::LinkObject'); return $Self; } =item Run() Create a new link. my $Result = $OperationObject->Run( Data => { SourceObject => 'Ticket',see L<http://www.gnu.org/licenses/agpl.txt>. =cut
今天关于如何使用php中的curl通过mongolab rest api创建基本数据库操作的web服务?和php 操作mongodb的分享就到这里,希望大家有所收获,若想了解更多关于.net – 如何使用HttpWebRequest来调用接受byte []参数的Web服务操作?、Erlang YAWS:如何测试简单的REST Web服务?、java – Restful Web服务如何比基于SOAP的Web服务更好、perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单等相关知识,可以在本站进行查询。
本文标签: