public void writeLogMessage(String strMsg) { IDictionary <object, object> map = new Dictionary <object, object>(); Hash values = new Hash(map); values.Add(CRhoRuby.CreateSymbol("url"), MutableString.Create(m_URL)); values.Add(CRhoRuby.CreateSymbol("body"), MutableString.Create(strMsg)); RhoParams p = new RhoParams(values); m_aHttp.addHttpCommand(new CAsyncHttp.HttpCommand("POST", p)); }
public HttpCommand(String strCmd, RhoParams p) { m_params = new RhoParams(p); m_eCmd = translateCommand(strCmd); m_strCallback = m_params.getString("callback"); m_strCallbackParams = m_params.getString("callback_param"); m_mapHeaders = m_params.getHash("headers"); m_pNetRequest = RhoClassFactory.createNetRequest(); m_pNetRequest.sslVerifyPeer(m_params.getBool("ssl_verify_peer")); }
public static MutableString doRequest(RubyModule /*!*/ self, [NotNull] String command, Hash args) { MutableString res = null; try { CAsyncHttp.Create(); RhoParams p = new RhoParams(args); res = CAsyncHttp.getInstance().addHttpCommand(new CAsyncHttp.HttpCommand(command, p)); } catch (Exception ex) { Exception rubyEx = self.Context.CurrentException; if (rubyEx == null) { rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message); } LOG.ERROR("do_request", ex); throw rubyEx; } return(res); }
public void execute() { NetResponse resp = null; try { switch (m_eCmd) { case hcGet: ///m_pNetRequest.setIgnoreSuffixOnSim(false); resp = m_pNetRequest.doRequest(m_params.getString("http_command", "GET"), m_params.getString("url"), m_params.getString("body"), null, m_mapHeaders); break; case hcPost: ///m_pNetRequest.setIgnoreSuffixOnSim(false); resp = m_pNetRequest.doRequest(m_params.getString("http_command", "POST"), m_params.getString("url"), m_params.getString("body"), null, m_mapHeaders); break; case hcDownload: resp = m_pNetRequest.pullFile(m_params.getString("url"), m_params.getString("filename"), null, m_mapHeaders); break; case hcUpload: { Vector <NetRequest.MultipartItem> /*Ptr<net::CMultipartItem*>*/ arMultipartItems = new Vector <NetRequest.MultipartItem>(); RhoParamArray arParams = new RhoParamArray(m_params, "multipart"); if (arParams.size() > 0) { for (int i = 0; i < arParams.size(); i++) { RhoParams oItem = arParams.getItem(i); NetRequest.MultipartItem pItem = new NetRequest.MultipartItem(); String strBody = oItem.getString("body"); if (strBody.length() > 0) { pItem.m_strBody = strBody; pItem.m_strContentType = oItem.getString("content_type", "application/x-www-form-urlencoded"); } else { pItem.m_strFilePath = oItem.getString("filename"); pItem.m_strContentType = oItem.getString("content_type", "application/octet-stream"); } pItem.m_strName = oItem.getString("name"); pItem.m_strFileName = oItem.getString("filename_base"); arMultipartItems.addElement(pItem); } } else { NetRequest.MultipartItem pItem = new NetRequest.MultipartItem(); pItem.m_strFilePath = m_params.getString("filename"); pItem.m_strContentType = m_params.getString("file_content_type", "application/octet-stream"); pItem.m_strName = m_params.getString("name"); pItem.m_strFileName = m_params.getString("filename_base"); arMultipartItems.addElement(pItem); String strBody = m_params.getString("body"); if (strBody.length() > 0) { NetRequest.MultipartItem pItem2 = new NetRequest.MultipartItem(); pItem2.m_strBody = strBody; pItem2.m_strContentType = (String)m_mapHeaders.get("content-type"); arMultipartItems.addElement(pItem2); } } resp = m_pNetRequest.pushMultipartData(m_params.getString("url"), arMultipartItems, null, m_mapHeaders); break; } } if (!m_pNetRequest.isCancelled()) { processResponse(resp); callNotify(resp, 0); } }catch (IOException exc) { LOG.ERROR("command failed: " + m_eCmd + "url: " + m_params.getString("url"), exc); callNotify(null, RhoAppAdapter.ERR_NETWORK); }catch (Exception exc) { LOG.ERROR("command crashed: " + m_eCmd + "url: " + m_params.getString("url"), exc); callNotify(null, RhoAppAdapter.ERR_RUNTIME); } }