Hi Peter, Need your help again. This time I am trying to upload a file using curl_setopt in php5.5 and @ is deprecated as prefix. So , can you help me writing request body again. I have tried using CURLFile enabling safe upload but every time a txt file with all the data is getting uploaded.
This is the var_dump of postfields array(4) { ["name"]=> string(5) "test1" ["format"]=> string(4) "text" ["sizeBytes"]=> string(12) "I don't know" ["test file "]=> object(CURLFile)#1 (3) { ["name"]=> string(8) "test.txt" ["mime"]=> string(3) "txt" ["postname"]=> string(4) "test" } } and This is what I am getting by retrieve link {"name":"test1","format":"text","sizeBytes":"I don't know","test file ":{"name":"test.txt","mime":"txt","postname":"test"}} here is the relevant part of my code $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$params['url']); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $params['header']); var_dump(array_key_exists("filename",$params)); if(!array_key_exists("filename",$params)) curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($params['rqst'])); else { curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $cfile = curl_file_create($params['filename'],$params['mimeType'],'test'); $params['rqst']['test file ']= $cfile; var_dump( $params['rqst']); curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($params['rqst'])); } Thanks in advance On Sat, Jun 6, 2015 at 5:48 PM, Aman Singh <singh26.a...@gmail.com> wrote: > Thanks Peter Dietz , finally it's working now. > > On Fri, Jun 5, 2015 at 8:29 PM, Peter Dietz <pe...@longsight.com> wrote: > >> Hi Aman, >> >> You can test this example application to see the flow: >> https://github.com/DSpace-Labs/dspace-rest-requests >> >> The json you pass in, should look like: >> { >> "email" : "EMAIL", >> "password" : "PASSWORD" >> } >> >> So, debug what your passing in. And try it with something like chrome >> extension Advanced Rest Client. >> >> ________________ >> Peter Dietz >> Longsight >> www.longsight.com >> pe...@longsight.com >> p: 740-599-5005 x809 >> >> On Fri, Jun 5, 2015 at 10:19 AM, Aman Singh <singh26.a...@gmail.com> >> wrote: >> >>> hi mark, >>> Yeah thats just a placeholder for the mail, I'm passing the correct >>> email and password while testing. >>> >>> anything else that could be the problem. >>> >>> Thanks >>> >>> On Fri, Jun 5, 2015 at 7:34 PM, Mark H. Wood <mw...@iupui.edu> wrote: >>> >>>> On Fri, Jun 05, 2015 at 07:28:16PM +0530, Aman Singh wrote: >>>> > hi all, >>>> > >>>> > I am trying login in Dspace remote server and getting error 500 and >>>> log >>>> > file shown below . >>>> > HTTP Status 500 - org.codehaus.jackson.JsonParseException: Unexpected >>>> > character ('e' (code 101)): expected a valid value (number, String, >>>> array, >>>> > object, 'true', 'false' or 'null') >>>> > >>>> > *type* Exception report >>>> > >>>> > *message* *org.codehaus.jackson.JsonParseException: Unexpected >>>> character >>>> > ('e' (code 101)): expected a valid value (number, String, array, >>>> object, >>>> > 'true', 'false' or 'null')* >>>> > >>>> > *description* *The server encountered an internal error that >>>> prevented it >>>> > from fulfilling this request.* >>>> > >>>> > *exception* >>>> > >>>> > javax.servlet.ServletException: >>>> > org.codehaus.jackson.JsonParseException: Unexpected character ('e' >>>> > (code 101)): expected a valid value (number, String, array, object, >>>> > 'true', 'false' or 'null') >>>> > at [Source: org.apache.catalina.connector.CoyoteInputStream@3fe07138 >>>> ; >>>> > line: 1, column: 2] >>>> > >>>> >>>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420) >>>> > >>>> >>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) >>>> > >>>> >>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) >>>> > javax.servlet.http.HttpServlet.service(HttpServlet.java:729) >>>> > >>>> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) >>>> > >>>> > *root cause* >>>> > >>>> > org.codehaus.jackson.JsonParseException: Unexpected character ('e' >>>> > (code 101)): expected a valid value (number, String, array, object, >>>> > 'true', 'false' or 'null') >>>> > at [Source: org.apache.catalina.connector.CoyoteInputStream@3fe07138 >>>> ; >>>> > line: 1, column: 2] >>>> > >>>> org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432) >>>> > >>>> >>>> org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385) >>>> > >>>> >>>> org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306) >>>> > >>>> >>>> org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:2084) >>>> > >>>> >>>> org.codehaus.jackson.impl.Utf8StreamParser._nextTokenNotInObject(Utf8StreamParser.java:600) >>>> > >>>> >>>> org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:486) >>>> > >>>> >>>> org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2761) >>>> > >>>> org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2682) >>>> > >>>> org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308) >>>> > >>>> >>>> org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419) >>>> > >>>> >>>> com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139) >>>> > >>>> >>>> com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:488) >>>> > >>>> >>>> com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123) >>>> > >>>> >>>> com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46) >>>> > >>>> >>>> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153) >>>> > >>>> >>>> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203) >>>> > >>>> >>>> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) >>>> > >>>> >>>> com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) >>>> > >>>> >>>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) >>>> > >>>> >>>> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) >>>> > >>>> >>>> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) >>>> > >>>> >>>> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) >>>> > >>>> >>>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511) >>>> > >>>> >>>> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442) >>>> > >>>> >>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391) >>>> > >>>> >>>> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381) >>>> > >>>> >>>> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) >>>> > >>>> >>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) >>>> > >>>> >>>> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) >>>> > javax.servlet.http.HttpServlet.service(HttpServlet.java:729) >>>> > >>>> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) >>>> > >>>> > *note* *The full stack trace of the root cause is available in the >>>> Apache >>>> > Tomcat/8.0.21 logs.* >>>> > >>>> > >>>> > Php fcode which I am using for this purpose is below ... >>>> > >>>> > <?php >>>> > >>>> > >>>> > $header=['Content-Type:application/json','Accept:JSON']; >>>> > $ch = curl_init(); >>>> > >>>> > curl_setopt($ch, CURLOPT_URL,"http://localhost:8080/rest/login/"); >>>> > curl_setopt($ch, CURLOPT_POST, 1); >>>> > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // receive server >>>> response ... >>>> > curl_setopt($ch, CURLOPT_TIMEOUT, 4); >>>> > curl_setopt($ch, CURLOPT_HTTPHEADER, $header); >>>> > //curl_setopt($ch, CURLOPT_USERPWD, >>>> $your_username.':'.$your_password); >>>> > curl_setopt($ch, >>>> > >>>> CURLOPT_POSTFIELDS,http_build_query(array('email'=>'emailaddress','password'=>'passs'))); >>>> >>>> Should the above line not be: >>>> >>>> > >>>> CURLOPT_POSTFIELDS,http_build_query(array('email'=>$your_username,'password'=>$your_password))); >>>> >>>> > >>>> > >>>> > >>>> > $server_output = curl_exec ($ch); >>>> > echo $server_output; >>>> > // var_dump($server_output >>>> > if (curl_errno($ch)) { >>>> > print curl_error($ch); >>>> > } else { >>>> > >>>> > } >>>> > curl_close ($ch); >>>> > >>>> > >>>> > // further processing .... >>>> > ?> >>>> > >>>> > >>>> > If anyone can point out the error in my code and how to debug it ? >>>> > >>>> > Thanks in advance >>>> >>>> > >>>> ------------------------------------------------------------------------------ >>>> >>>> > _______________________________________________ >>>> > DSpace-tech mailing list >>>> > DSpace-tech@lists.sourceforge.net >>>> > https://lists.sourceforge.net/lists/listinfo/dspace-tech >>>> > List Etiquette: >>>> https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette >>>> >>>> >>>> -- >>>> Mark H. Wood >>>> Lead Technology Analyst >>>> >>>> University Library >>>> Indiana University - Purdue University Indianapolis >>>> 755 W. Michigan Street >>>> Indianapolis, IN 46202 >>>> 317-274-0749 >>>> www.ulib.iupui.edu >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> >>>> _______________________________________________ >>>> DSpace-tech mailing list >>>> DSpace-tech@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/dspace-tech >>>> List Etiquette: >>>> https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette >>>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> DSpace-tech mailing list >>> DSpace-tech@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/dspace-tech >>> List Etiquette: >>> https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette >>> >> >> >
------------------------------------------------------------------------------
_______________________________________________ DSpace-tech mailing list DSpace-tech@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dspace-tech List Etiquette: https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette