static search_result PerformBingImageSearch(string st) { string uri_key = "5c9869dfcf7a41859de8b2e066543bfe"; string endpoint = "https://mayank1234.cognitiveservices.azure.com/bing/v7.0/images/search"; string uriQuery = endpoint + "?q=" + Uri.EscapeDataString(st); WebRequest request = WebRequest.Create(uriQuery); request.Headers["Ocp-Apim-Subscription-Key"] = uri_key; HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result; string json = new StreamReader(response.GetResponseStream()).ReadToEnd(); var searchResult = new search_result() { jsonResult = json, headers_r = new Dictionary <String, String>() }; // Extract the Bing HTTP headers. foreach (String header in response.Headers) { if (header.StartsWith("BingAPIs-") || header.StartsWith("X-MSEdge-")) { searchResult.headers_r[header] = response.Headers[header]; } } return(searchResult); }
public void search_Process(int seqid, TProtocol iprot, TProtocol oprot) { search_args args = new search_args(); args.Read(iprot); iprot.ReadMessageEnd(); search_result result = new search_result(); try { result.Success = iface_.search(args.Word); oprot.WriteMessageBegin(new TMessage("search", TMessageType.Reply, seqid)); result.Write(oprot); } catch (TTransportException) { throw; } catch (Exception ex) { Console.Error.WriteLine("Error occurred in processor:"); Console.Error.WriteLine(ex.ToString()); TApplicationException x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error."); oprot.WriteMessageBegin(new TMessage("search", TMessageType.Exception, seqid)); x.Write(oprot); } oprot.WriteMessageEnd(); oprot.Transport.Flush(); }
public void search_Process(int seqid, TProtocol iprot, TProtocol oprot) { search_args args = new search_args(); args.Read(iprot); iprot.ReadMessageEnd(); search_result result = new search_result(); try { result.Success = iface_.search(args.Search); } catch (com.imd.common.thrift.ThriftException e) { result.E = e; } oprot.WriteMessageBegin(new TMessage("search", TMessageType.Reply, seqid)); result.Write(oprot); oprot.WriteMessageEnd(); oprot.Transport.Flush(); }
public string FindURLOfImage(string st) { // call the method that does the search search_result result = PerformBingImageSearch(st); JsonObject jsonObj = JsonObject.Parse(result.jsonResult); JsonArray results = jsonObj.GetNamedArray("value"); if (results.Count > 0) { JsonObject first_result = results.GetObjectAt(0); String imageUrl = first_result.GetNamedString("contentUrl"); return(imageUrl); } else { return("https://cdn.techinasia.com/wp-content/uploads/2016/06/why-are-you-so-dumb.jpg"); } }
public string recv_search() { TMessage msg = iprot_.ReadMessageBegin(); if (msg.Type == TMessageType.Exception) { TApplicationException x = TApplicationException.Read(iprot_); iprot_.ReadMessageEnd(); throw x; } search_result result = new search_result(); result.Read(iprot_); iprot_.ReadMessageEnd(); if (result.__isset.success) { return(result.Success); } throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "search failed: unknown result"); }